Skip to content

Commit 7347ca3

Browse files
authored
Merge pull request #1 from netlify/roles
add configuration for roles
2 parents 4c7c542 + 0d7c9e7 commit 7347ca3

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,22 @@
11
# git-gateway - Gateway to hosted git APIs
2+
3+
**Secure role based access to the APIs of common Git Hosting providers.**
4+
5+
When building sites with a JAMstack approach, a common pattern is to store all content as structured data in a Git repository instead of relying on an external database.
6+
7+
Netlify CMS is an open-source content management UI that allows content editors to work with your content in Git through a familiar content editing interface. This allows people to write and edit content without having to write code or know anything about Git, markdown, YAML, JSON, etc.
8+
9+
However, for most use cases you won’t want to require all content editors to have a GitHub account with full access to the source code repository for your website.
10+
11+
Netlify’s Git Gateway lets you setup a gateway to GitHub’s API (more providers coming) that lets tools like Netlify CMS work with content, branches and pull requests on your users’ behalf.
12+
13+
The Git Gateway works with any identity service that can issue JWTs and only allows access when a JSON Web Token with sufficient permissions is present.
14+
15+
To configure the gateway, see our example.env file
16+
17+
The Gateway limits access to the following sub endpoints of the repository:
18+
19+
/repos/:owner/:name/git/
20+
/repos/:owner/:name/contents/
21+
/repos/:owner/:name/pulls/
22+
/repos/:owner/:name/branches/

api/github.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ func (gh *GitHubGateway) authenticate(w http.ResponseWriter, r *http.Request) er
101101
return errors.New("Access to endpoint not allowed: this part of GitHub's API has been restricted")
102102
}
103103

104+
if len(adminRoles) == 0 {
105+
return nil
106+
}
107+
104108
roles, ok := claims.AppMetaData["roles"]
105109
if ok {
106110
roleStrings, _ := roles.([]interface{})

conf/configuration.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type GlobalConfiguration struct {
4545
type Configuration struct {
4646
JWT JWTConfiguration `json:"jwt"`
4747
GitHub GitHubConfig `envconfig:"GITHUB" json:"github"`
48+
Roles []string `envconfig:"ROLES" json:"roles"`
4849
}
4950

5051
func loadEnvironment(filename string) error {

example.env

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
GITGATEWAY_JWT_SECRET="CHANGE-THIS! VERY IMPORTANT!"
2+
23
GITGATEWAY_DB_DRIVER=sqlite3
34
DATABASE_URL=gorm.db
5+
46
GITGATEWAY_API_HOST=localhost
57
PORT=9999
8+
9+
GITGATEWAY_GITHUB_ACCESS_TOKEN="personal-access-token"
10+
GITGATEWAY_GITHUB_REPO="owner/name"
11+
12+
GITGATEWAY_ROLES="admin,cms" # leave blank to allow all roles

0 commit comments

Comments
 (0)