Skip to content

Commit 88f739c

Browse files
committed
rename claims
1 parent da2a93d commit 88f739c

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ Allowed JWT claims are:
6161

6262
- exp - int, expiration (unix time)
6363
- nbf - int, not before (unix time)
64-
- allowedAPIMethods - string, comma seperated list of allowed API methods (e.g. is "get,post")
65-
- allowedAPIRegexp - string, a reular expresion of allowed api call paths.
64+
- matchMethod - string, comma seperated list of allowed API methods (e.g. is "get,post")
65+
- matchPath - string, a reular expresion of allowed api call paths.
6666

6767
![alt demo gif](https://raw.githubusercontent.com/yaacov/oc-gate/main/web/public/custom_tokens.gif)
6868

deploy/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ Create a JWT specific for the k8s object you want to allow holder of this JWT to
6363

6464
``` bash
6565
# To sign the JWT use the private key that belong to the public key in the running oc-gate
66-
# The "allowedAPIRegexp" claim use regexp to allow specific k8s path
66+
# The "matchPath" claim use regexp to allow specific k8s path
6767
# use '^' to force start of path, and '$' to force end of path.
68-
# Other claims the proxy will respect are: allowedAPIMethods, exp and nbf
68+
# Other claims the proxy will respect are: matchMethod, exp and nbf
6969

7070
# Create a token with path restriction,
71-
echo {\"allowedAPIRegexp\":\"^/k8s/api/v1/pods\"} | jwt -key ./test/key.pem -alg RS256 -sign -
71+
echo {\"matchPath\":\"^/k8s/api/v1/pods\"} | jwt -key ./test/key.pem -alg RS256 -sign -
7272

7373
# Create a token with experation date and allowed API path
74-
echo {\"exp\": $(expr $(date +%s) + 100),\"allowedAPIRegexp\":\"^/k8s/api/v1/namespaces/test\"} | jwt -key ./test/key.pem -alg RS256 -sign -
74+
echo {\"exp\": $(expr $(date +%s) + 100),\"matchPath\":\"^/k8s/api/v1/namespaces/test\"} | jwt -key ./test/key.pem -alg RS256 -sign -
7575
```
7676

7777
This token can now be given to a user that will have access only to this specific k8s object(s).

pkg/proxy/token.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ func handleError(w http.ResponseWriter, err error) {
1616
fmt.Fprintf(w, "{\"kind\": \"Status\", \"api\": \"ocgate\", \"status\": \"Forbidden\", \"message\": \"%s\",\"code\": %d}", err, http.StatusForbidden)
1717
}
1818

19-
func validateRequest(httpMethod string, httpPath string, apiPAth string, allowedAPIMethods string, k8sAllowedAPIRegexp *regexp.Regexp) error {
19+
func validateRequest(httpMethod string, httpPath string, apiPAth string, matchMethod string, matchPathRegexp *regexp.Regexp) error {
2020
// Validate method
21-
if allowedAPIMethods != "" {
22-
if !strings.Contains(allowedAPIMethods, strings.ToLower(httpMethod)) {
21+
if matchMethod != "" {
22+
if !strings.Contains(strings.ToLower(matchMethod), strings.ToLower(httpMethod)) {
2323
return fmt.Errorf("%s method not allowedd", httpMethod)
2424
}
2525
}
@@ -29,7 +29,7 @@ func validateRequest(httpMethod string, httpPath string, apiPAth string, allowed
2929
if len(httpPath) > len(apiPAth) &&
3030
httpPath[:len(apiPAth)] == apiPAth &&
3131
httpPath[len(apiPAth):] != "/.well-known/oauth-authorization-server" &&
32-
!k8sAllowedAPIRegexp.MatchString(httpPath) {
32+
!matchPathRegexp.MatchString(httpPath) {
3333
return fmt.Errorf("%s path not allowed", httpPath)
3434
}
3535

@@ -53,18 +53,18 @@ func validateToken(token string, secret []byte, publicKey *rsa.PublicKey, apiPat
5353
}
5454

5555
if claims, ok := tok.Claims.(jwt.MapClaims); ok && tok.Valid {
56-
var allowedAPIMethods string
57-
var allowedAPIRegexp string
56+
var matchMethod string
57+
var matchPath string
5858

59-
if allowedAPIMethods, ok = claims["allowedAPIMethods"].(string); !ok {
60-
allowedAPIMethods = ""
59+
if matchMethod, ok = claims["matchMethod"].(string); !ok {
60+
matchMethod = ""
6161
}
62-
if allowedAPIRegexp, ok = claims["allowedAPIRegexp"].(string); !ok {
63-
allowedAPIRegexp = ""
62+
if matchPath, ok = claims["matchPath"].(string); !ok {
63+
matchPath = ""
6464
}
65-
k8sAllowedAPIRegexp := regexp.MustCompile(allowedAPIRegexp)
65+
matchPathRegexp := regexp.MustCompile(matchPath)
6666

67-
err := validateRequest(httpMethod, httpPath, apiPath, allowedAPIMethods, k8sAllowedAPIRegexp)
67+
err := validateRequest(httpMethod, httpPath, apiPath, matchMethod, matchPathRegexp)
6868
if err != nil {
6969
return nil, err
7070
}

0 commit comments

Comments
 (0)