Skip to content

Commit

Permalink
Set --service-account-issuer for k8s 1.20+
Browse files Browse the repository at this point in the history
  • Loading branch information
johngmyers committed Nov 21, 2020
1 parent bdfa785 commit 9607b99
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
26 changes: 14 additions & 12 deletions pkg/model/components/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (b *DiscoveryOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec := o.(*kops.ClusterSpec)

useJWKS := featureflag.PublicJWKS.Enabled()
if !useJWKS {
if !useJWKS && b.IsKubernetesLT("1.20") {
return nil
}

Expand All @@ -46,11 +46,6 @@ func (b *DiscoveryOptionsBuilder) BuildOptions(o interface{}) error {

kubeAPIServer := clusterSpec.KubeAPIServer

if kubeAPIServer.FeatureGates == nil {
kubeAPIServer.FeatureGates = make(map[string]string)
}
kubeAPIServer.FeatureGates["ServiceAccountIssuerDiscovery"] = "true"

if len(kubeAPIServer.APIAudiences) == 0 {
kubeAPIServer.APIAudiences = []string{"kubernetes.svc.default"}
}
Expand All @@ -63,14 +58,21 @@ func (b *DiscoveryOptionsBuilder) BuildOptions(o interface{}) error {
kubeAPIServer.ServiceAccountIssuer = &serviceAccountIssuer
}

if kubeAPIServer.ServiceAccountJWKSURI == nil {
jwksURL := *kubeAPIServer.ServiceAccountIssuer
jwksURL = strings.TrimSuffix(jwksURL, "/") + "/openid/v1/jwks"
// We set apiserver ServiceAccountKey and ServiceAccountSigningKeyFile in nodeup

kubeAPIServer.ServiceAccountJWKSURI = &jwksURL
}
if useJWKS {
if kubeAPIServer.FeatureGates == nil {
kubeAPIServer.FeatureGates = make(map[string]string)
}
kubeAPIServer.FeatureGates["ServiceAccountIssuerDiscovery"] = "true"

// We set apiserver ServiceAccountKey and ServiceAccountSigningKeyFile in nodeup
if kubeAPIServer.ServiceAccountJWKSURI == nil {
jwksURL := *kubeAPIServer.ServiceAccountIssuer
jwksURL = strings.TrimSuffix(jwksURL, "/") + "/openid/v1/jwks"

kubeAPIServer.ServiceAccountJWKSURI = &jwksURL
}
}

return nil
}
1 change: 0 additions & 1 deletion pkg/model/iam/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ go_library(
deps = [
"//pkg/apis/kops:go_default_library",
"//pkg/apis/kops/model:go_default_library",
"//pkg/featureflag:go_default_library",
"//pkg/util/stringorslice:go_default_library",
"//pkg/wellknownusers:go_default_library",
"//upup/pkg/fi:go_default_library",
Expand Down
7 changes: 1 addition & 6 deletions pkg/model/iam/subject.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/pkg/featureflag"
"k8s.io/kops/pkg/wellknownusers"
)

Expand Down Expand Up @@ -83,11 +82,7 @@ func BuildNodeRoleSubject(igRole kops.InstanceGroupRole) (Subject, error) {

// ServiceAccountIssuer determines the issuer in the ServiceAccount JWTs
func ServiceAccountIssuer(clusterName string, clusterSpec *kops.ClusterSpec) (string, error) {
if featureflag.PublicJWKS.Enabled() {
return "https://api." + clusterName, nil
}

return "", fmt.Errorf("ServiceAcccountIssuer not (currently) supported without PublicJWKS")
return "https://api." + clusterName, nil
}

// AddServiceAccountRole adds the appropriate mounts / env vars to enable a pod to use a service-account role
Expand Down

0 comments on commit 9607b99

Please sign in to comment.