-
-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jwt validation #171
jwt validation #171
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -142,3 +142,28 @@ CACHE_ALLOWED_STATUSES=200,301,302 | |||||
# though it is recommended to specify them explicitly. | ||||||
# Default: HEAD,GET | ||||||
CACHE_ALLOWED_METHODS=HEAD,GET | ||||||
|
||||||
# --- JWT | ||||||
# A list of space-separated paths. | ||||||
# JWT_EXCLUDED_PATHS= | ||||||
|
||||||
# A list of space-separated scopes to be allowed. | ||||||
# JWT_ALLOWED_SCOPES= | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use the same example values from
Suggested change
|
||||||
|
||||||
# The JSON Web Key Set (JWKS) URL where it is stored the the public keys used to verify the JSON Web Token (JWT). | ||||||
# - For global configuration: | ||||||
# JWT_JWKS_URL= | ||||||
# - For domain configuration: | ||||||
# JWT_JWKS_URL_<domain_name_specified_in_config.yml>= | ||||||
# *e.g: JWT_JWKS_URL_example_com=http://testJwksUrl.com | ||||||
# Global Configuration - The value of the JwksUrl field is taken by following this preference order: | ||||||
# - JWT_JWKS_URL enviroment variable | ||||||
# - global jwks_url variable in config.yaml | ||||||
# Domain Configuration - The value of the JwksUrl field is taken by following this preference order: | ||||||
# - JWT_JWKS_URL_<domain_name_specified_in_config.yml> enviroment variable | ||||||
# - domain jwks_url variable specified in config.yaml | ||||||
# - global jwks_url variable specified in config.yaml | ||||||
# - JWT_JWKS_URL enviroment variable | ||||||
|
||||||
# Time in minutes that takes for JWKS to refresh automatically | ||||||
# JWT_REFRESH_INTERVAL= | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use the same example values from
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -306,6 +306,19 @@ tracing: | |
# Default: 1.0 | ||
sampling_ratio: 1.0 | ||
|
||
# --- JWT (careful, setting JWT config here affects all domains) | ||
# jwt: | ||
# # A list of space-separated paths. | ||
# excluded_paths: | ||
# - / | ||
# # A list of space-separated scopes to be allowed. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space or comma separated? |
||
# allowed_scopes: | ||
# - scope1, scope2 | ||
# # The JSON Web Key Set (JWKS) URL where it is stored the the public keys used to verify the JSON Web Token (JWT). | ||
# jwks_url: ~ | ||
# # Time in minutes that takes for JWKS to refresh automatically | ||
# jwks_refresh_interval: 15 | ||
|
||
### PER DOMAIN CONFIGURATION OVERRIDE | ||
################################################################################ | ||
domains: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,12 +10,15 @@ package config | |
// Repo: https://github.com/fabiocicerchia/go-proxy-cache | ||
|
||
import ( | ||
"context" | ||
"crypto/tls" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/fabiocicerchia/go-proxy-cache/utils" | ||
circuitbreaker "github.com/fabiocicerchia/go-proxy-cache/utils/circuit-breaker" | ||
"github.com/lestrrat-go/jwx/v2/jwk" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// DefaultTimeoutRead - Default value used for http.Server.ReadTimeout | ||
|
@@ -57,6 +60,7 @@ type Configuration struct { | |
Log Log `yaml:"log"` | ||
Tracing Tracing `yaml:"tracing"` | ||
domainsCache map[string]Configuration | ||
Jwt Jwt `yaml:"jwt"` | ||
} | ||
|
||
// Domains - Overrides per domain. | ||
|
@@ -162,6 +166,23 @@ type DomainSet struct { | |
Scheme string | ||
} | ||
|
||
// Jwt - Defines the config for the jwt validation. | ||
type Jwt struct { | ||
ExcludedPaths []string `yaml:"excluded_paths" envconfig:"JWT_EXCLUDED_PATHS" split_words:"true"` | ||
AllowedScopes []string `yaml:"allowed_scopes" envconfig:"JWT_ALLOWED_SCOPES" split_words:"true"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
JwksUrl string `yaml:"jwks_url" envconfig:"JWT_JWKS_URL"` | ||
JwksRefreshInterval int `yaml:"jwks_refresh_interval" envconfig:"JWT_REFRESH_INTERVAL" default:"15"` | ||
JwkCache *jwk.Cache | ||
Context context.Context | ||
Logger *logrus.Logger | ||
} | ||
|
||
// Jwt - Defines the jwt validation error. | ||
type JwtError struct { | ||
ErrorCode string `json:"errorCode"` | ||
ErrorDescription string `json:"errorDescription"` | ||
} | ||
|
||
// Config - Holds the server configuration. | ||
var Config Configuration = Configuration{ | ||
Server: Server{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,11 @@ | |
- `TLS_KEY_FILE` | ||
- `TRACING_ENABLED` | ||
- `TRACING_JAEGER_ENDPOINT` | ||
- `JWT_EXCLUDED_PATHS` | ||
- `JWT_ALLOWED_SCOPES` | ||
- `JWT_JWKS_URL` | ||
- `JWT_JWKS_URL_<domain_name_specified_in_config.yml>` | ||
- `JWT_REFRESH_INTERVAL` | ||
|
||
## YAML | ||
|
||
|
@@ -353,6 +358,19 @@ tracing: | |
# Default: 1.0 | ||
sampling_ratio: 1.0 | ||
|
||
# --- JWT | ||
# jwt: | ||
# # A list of space-separated paths. | ||
# excluded_paths: | ||
# - / | ||
# # A list of space-separated scopes to be allowed. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to clarify if it is space or comma separated |
||
# allowed_scopes: | ||
# - scope1, scope2 | ||
# # The JSON Web Key Set (JWKS) URL where it is stored the the public keys used to verify the JSON Web Token (JWT). | ||
# jwks_url: ~ | ||
# # Time in minutes that takes for JWKS to refresh automatically | ||
# jwks_refresh_interval: 15 | ||
|
||
### PER DOMAIN CONFIGURATION OVERRIDE | ||
################################################################################ | ||
domains: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the same example values from
config.yml.dist
: