Skip to content

Commit 670377f

Browse files
authored
Merge pull request #329 from stlaz/auds_check
explicitly require OIDC audience for the OIDC authenticator
2 parents 36f06fa + 13e8a89 commit 670377f

File tree

6 files changed

+16
-6
lines changed

6 files changed

+16
-6
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ Proxy flags:
109109
OIDC flags:
110110
111111
--oidc-ca-file string If set, the OpenID server's certificate will be verified by one of the authorities in the oidc-ca-file, otherwise the host's root CA set will be used.
112-
--oidc-clientID string The client ID for the OpenID Connect client, must be set if oidc-issuer-url is set.
113112
--oidc-groups-claim string Identifier of groups in JWT claim, by default set to 'groups' (default "groups")
114113
--oidc-groups-prefix string If provided, all groups will be prefixed with this value to prevent conflicts with other authentication strategies.
115114
--oidc-issuer string The URL of the OpenID issuer, only HTTPS scheme will be accepted. If set, it will be used to verify the OIDC JSON Web Token (JWT).
115+
--oidc-required-audience aud The audience that must appear in all incoming tokens' aud claim. Must be set if `oidc-issuer` is configured.
116116
--oidc-sign-alg stringArray Supported signing algorithms, default RS256 (default [RS256])
117117
--oidc-username-claim string Identifier of the user in JWT claim, by default set to 'email' (default "email")
118118
--oidc-username-prefix string If provided, the username will be prefixed with this value to prevent conflicts with other authentication strategies.

cmd/kube-rbac-proxy/app/options/oidcoptions.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package options
1818

1919
import (
20+
"fmt"
21+
2022
"github.com/brancz/kube-rbac-proxy/pkg/authn"
2123
"github.com/brancz/kube-rbac-proxy/pkg/server"
2224
"github.com/spf13/pflag"
@@ -29,7 +31,7 @@ type OIDCOptions struct {
2931
func (o *OIDCOptions) AddFlags(flagset *pflag.FlagSet) {
3032
// Authn OIDC flags
3133
flagset.StringVar(&o.IssuerURL, "oidc-issuer", "", "The URL of the OpenID issuer, only HTTPS scheme will be accepted. If set, it will be used to verify the OIDC JSON Web Token (JWT).")
32-
flagset.StringVar(&o.ClientID, "oidc-clientID", "", "The client ID for the OpenID Connect client, must be set if oidc-issuer-url is set.")
34+
flagset.StringVar(&o.RequiredAudience, "oidc-required-audience", "", "The audience that must appear in all incoming tokens' `aud` claim. Must be set if `oidc-issuer` is configured.")
3335
flagset.StringVar(&o.UsernameClaim, "oidc-username-claim", "email", "Identifier of the user in JWT claim, by default set to 'email'")
3436
flagset.StringVar(&o.GroupsClaim, "oidc-groups-claim", "groups", "Identifier of groups in JWT claim, by default set to 'groups'")
3537
flagset.StringVar(&o.UsernamePrefix, "oidc-username-prefix", "", "If provided, the username will be prefixed with this value to prevent conflicts with other authentication strategies.")
@@ -41,6 +43,14 @@ func (o *OIDCOptions) AddFlags(flagset *pflag.FlagSet) {
4143

4244
func (o *OIDCOptions) Validate() []error {
4345
var errs []error
46+
if len(o.IssuerURL) == 0 {
47+
return errs
48+
}
49+
50+
if len(o.RequiredAudience) == 0 {
51+
errs = append(errs, fmt.Errorf("oidc-required-audience must be set when `oidc-issuer` is configured"))
52+
}
53+
4454
return errs
4555
}
4656

examples/oidc/deployment.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ spec:
7272
- "--upstream=http://127.0.0.1:8081/"
7373
- "--v=10"
7474
- "--oidc-issuer={ISSUER}"
75-
- "--oidc-clientID={CLIENT_ID}"
75+
- "--oidc-required-audience={CLIENT_ID}"
7676
ports:
7777
- containerPort: 8443
7878
name: https

pkg/authn/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type TokenConfig struct {
3131
// OIDCConfig represents configuration used for JWT request authentication
3232
type OIDCConfig struct {
3333
IssuerURL string
34-
ClientID string
34+
RequiredAudience string
3535
CAFile string
3636
UsernameClaim string
3737
UsernamePrefix string

pkg/authn/oidc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func NewOIDCAuthenticator(ctx context.Context, config *OIDCConfig) (*OIDCAuthent
4747
JWTAuthenticator: apiserver.JWTAuthenticator{
4848
Issuer: apiserver.Issuer{
4949
URL: config.IssuerURL,
50-
Audiences: []string{config.ClientID},
50+
Audiences: []string{config.RequiredAudience},
5151
},
5252
ClaimMappings: apiserver.ClaimMappings{
5353
Username: apiserver.PrefixedClaimOrExpression{

scripts/templates/oidc-deployment.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ spec:
7272
- "--upstream=http://127.0.0.1:8081/"
7373
- "--v=10"
7474
- "--oidc-issuer={ISSUER}"
75-
- "--oidc-clientID={CLIENT_ID}"
75+
- "--oidc-required-audience={CLIENT_ID}"
7676
ports:
7777
- containerPort: 8443
7878
name: https

0 commit comments

Comments
 (0)