Skip to content
This repository has been archived by the owner on Feb 9, 2022. It is now read-only.

GKE: Restrict Oauth authentication by domain suffix #177

Merged
merged 1 commit into from
Oct 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions kubeprod/pkg/aks/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ import (
)

const (
flagEmail = "email"
flagDNSSuffix = "dns-zone"
flagSubID = "subscription-id"
flagTenantID = "tenant-id"
flagDNSResgrp = "dns-resource-group"
flagEmail = "email"
flagDNSSuffix = "dns-zone"
flagAuthzDomain = "authz-domain"
flagSubID = "subscription-id"
flagTenantID = "tenant-id"
flagDNSResgrp = "dns-resource-group"
)

func defaultSubscription() *azcli.Subscription {
Expand Down Expand Up @@ -81,7 +82,7 @@ func init() {
}

aksCmd.PersistentFlags().String(flagEmail, os.Getenv("EMAIL"), "Contact email for cluster admin")

aksCmd.PersistentFlags().String(flagAuthzDomain, "*", "Restrict authorized users to this email domain. Default '*' allows all users in Azure tenant.")
aksCmd.PersistentFlags().String(flagSubID, defSubID, "Azure subscription ID")
aksCmd.PersistentFlags().String(flagTenantID, defTenantID, "Azure tenant ID")
aksCmd.PersistentFlags().String(flagDNSSuffix, "", "External DNS zone for public endpoints")
Expand Down
8 changes: 8 additions & 0 deletions kubeprod/pkg/aks/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ func (conf *AKSConfig) Generate(ctx context.Context) error {
conf.OauthProxy.ClientSecret = secret
}

if conf.OauthProxy.AuthzDomain == "" {
domain, err := flags.GetString(flagAuthzDomain)
if err != nil {
return err
}
conf.OauthProxy.AuthzDomain = domain
}

if conf.OauthProxy.AzureTenant == "" {
tenantID, err := flags.GetString(flagTenantID)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions kubeprod/pkg/aks/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type OauthProxyConfig struct {
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"`
CookieSecret string `json:"cookie_secret"`
AuthzDomain string `json:"authz_domain"`
AzureTenant string `json:"azure_tenant"`
}

Expand Down
3 changes: 3 additions & 0 deletions kubeprod/pkg/gke/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
flagEmail = "email"
flagDNSSuffix = "dns-zone"
flagProject = "project"
flagAuthzDomain = "authz-domain"
flagOauthClientId = "oauth-client-id"
flagOauthClientSecret = "oauth-client-secret"
flagOauthGoogleGroups = "oauth-google-groups"
Expand All @@ -55,6 +56,8 @@ func init() {

gkeCmd.PersistentFlags().String(flagEmail, os.Getenv("EMAIL"), "Contact email for cluster admin")
gkeCmd.PersistentFlags().String(flagDNSSuffix, "", "External DNS zone for public endpoints")
gkeCmd.PersistentFlags().String(flagAuthzDomain, "", "Restrict authorized users to this Google email domain")
gkeCmd.MarkPersistentFlagRequired(flagAuthzDomain)
gkeCmd.PersistentFlags().String(flagProject, "", "GCP project to use for managed resources")
gkeCmd.PersistentFlags().String(flagOauthClientId, "", "Client ID to use for OAuth")
gkeCmd.PersistentFlags().String(flagOauthClientSecret, "", "Client secret to use for OAuth")
Expand Down
8 changes: 8 additions & 0 deletions kubeprod/pkg/gke/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,14 @@ func (conf *GKEConfig) Generate(ctx context.Context) error {
conf.OauthProxy.CookieSecret = secret
}

if conf.OauthProxy.AuthzDomain == "" {
domain, err := flags.GetString(flagAuthzDomain)
if err != nil {
return err
}
conf.OauthProxy.AuthzDomain = domain
}

if conf.OauthProxy.GoogleGroups == nil {
// Avoid json `null`
groups, err := flags.GetStringSlice(flagOauthGoogleGroups)
Expand Down
1 change: 1 addition & 0 deletions kubeprod/pkg/gke/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type OauthProxyConfig struct {
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"`
CookieSecret string `json:"cookie_secret"`
AuthzDomain string `json:"authz_domain"`
GoogleGroups []string `json:"google_groups"`
GoogleAdminEmail string `json:"google_admin_email"`
GoogleServiceAccountJson string `json:"google_service_account_json"`
Expand Down
1 change: 1 addition & 0 deletions manifests/platforms/aks.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ local kibana = import "../components/kibana.jsonnet";
containers_+: {
proxy+: {
args_+: {
"email-domain": $.config.oauthProxy.authz_domain,
provider: "azure",
},
env_+: {
Expand Down
1 change: 1 addition & 0 deletions manifests/platforms/gke.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ local kibana = import "../components/kibana.jsonnet";
containers_+: {
proxy+: {
args_+: {
"email-domain": $.config.oauthProxy.authz_domain,
provider: "google",
"google-service-account-json": if $.config.oauthProxy.google_service_account_json != "" then "/google/credentials.json" else "",
"google-admin-email": $.config.oauthProxy.google_admin_email,
Expand Down
1 change: 1 addition & 0 deletions manifests/tests/aks.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
client_id: "myclientid",
client_secret: "mysecret",
cookie_secret: "cookiesecret",
authz_domain: "test.invalid",
azure_tenant: "mytenant",
},
},
Expand Down
1 change: 1 addition & 0 deletions manifests/tests/gke.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
client_id: "myclientid",
client_secret: "mysecret",
cookie_secret: "cookiesecret",
authz_domain: "test.invalid",
google_groups: [],
google_admin_email: "admin@example.com",
google_service_account_json: "<fake google credentials json contents>",
Expand Down