Skip to content

Commit e36d479

Browse files
authored
Validate signer for AWS ALB header (#680)
1 parent ced8f53 commit e36d479

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

configs/config.hcl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ okta {
210210

211211
// disabled disables Okta authorization.
212212
disabled = true
213+
214+
// jwt_signer is the trusted signer for the ALB JWT header.
215+
jwt_signer = ""
213216
}
214217

215218
// postgres configures PostgreSQL as the app database.

internal/auth/oktaalb/oktaalb.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ type Config struct {
3737

3838
// Disabled disables Okta authorization.
3939
Disabled bool `hcl:"disabled,optional"`
40+
41+
// JWTSigner is the trusted signer for the ALB JWT header.
42+
JWTSigner string `hcl:"jwt_signer,optional"`
4043
}
4144

4245
// New returns a new Okta authorizer.
@@ -72,6 +75,10 @@ func (oa *OktaAuthorizer) EnforceOktaAuth(next http.Handler) http.Handler {
7275
// verifyOIDCToken checks if the request is authorized and returns the user
7376
// identity.
7477
func (oa *OktaAuthorizer) verifyOIDCToken(r *http.Request) (string, error) {
78+
if oa.cfg.JWTSigner == "" {
79+
return "", fmt.Errorf("JWT signer not configured")
80+
}
81+
7582
// Get the key ID from JWT headers (the kid field).
7683
encodedJWT := r.Header.Get("x-amzn-oidc-data")
7784
if encodedJWT == "" {
@@ -96,6 +103,15 @@ func (oa *OktaAuthorizer) verifyOIDCToken(r *http.Request) (string, error) {
96103
return "", fmt.Errorf("kid not found in decoded JSON")
97104
}
98105

106+
// Validate signer.
107+
signer, ok := decodedJSON["signer"].(string)
108+
if !ok {
109+
return "", fmt.Errorf("signer not found in decoded JSON")
110+
}
111+
if signer != oa.cfg.JWTSigner {
112+
return "", fmt.Errorf("unexpected signer: %s", signer)
113+
}
114+
99115
// Get the public key from the regional endpoint.
100116
url := fmt.Sprintf("https://public-keys.auth.elb.%s.amazonaws.com/%s",
101117
oa.cfg.AWSRegion, kid)

internal/cmd/commands/server/server.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ func (c *Command) Run(args []string) int {
144144
cfg.Okta.Disabled = true
145145
}
146146
}
147+
if val, ok := os.LookupEnv("HERMES_SERVER_OKTA_JWT_SIGNER"); ok {
148+
cfg.Okta.JWTSigner = val
149+
}
147150
if c.flagOktaDisabled {
148151
cfg.Okta.Disabled = true
149152
}
@@ -193,6 +196,10 @@ func (c *Command) Run(args []string) int {
193196
c.UI.Error("error initializing server: Okta client ID is required")
194197
return 1
195198
}
199+
if cfg.Okta.JWTSigner == "" {
200+
c.UI.Error("error initializing server: Okta JWT signer is required")
201+
return 1
202+
}
196203
}
197204

198205
// Initialize Datadog.

0 commit comments

Comments
 (0)