Skip to content
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

Adds support for using OS application credentials #9702

Merged
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
2 changes: 2 additions & 0 deletions nodeup/pkg/bootstrap/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ func (i *Installation) buildSystemdJob() *nodetasks.Service {
"OS_PASSWORD",
"OS_AUTH_URL",
"OS_REGION_NAME",
"OS_APPLICATION_CREDENTIAL_ID",
"OS_APPLICATION_CREDENTIAL_SECRET",
} {
buffer.WriteString("'")
buffer.WriteString(envVar)
Expand Down
2 changes: 2 additions & 0 deletions nodeup/pkg/model/cloudconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ func (b *CloudConfigBuilder) Build(c *fi.ModelBuilderContext) error {
fmt.Sprintf("tenant-name=\"%s\"", tenantName),
fmt.Sprintf("domain-name=\"%s\"", os.Getenv("OS_DOMAIN_NAME")),
fmt.Sprintf("domain-id=\"%s\"", os.Getenv("OS_DOMAIN_ID")),
fmt.Sprintf("application-credential-id=\"%s\"", os.Getenv("OS_APPLICATION_CREDENTIAL_ID")),
fmt.Sprintf("application-credential-secret=\"%s\"", os.Getenv("OS_APPLICATION_CREDENTIAL_SECRET")),
hakman marked this conversation as resolved.
Show resolved Hide resolved
"",
hakman marked this conversation as resolved.
Show resolved Hide resolved
)

Expand Down
2 changes: 2 additions & 0 deletions nodeup/pkg/model/protokube.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,8 @@ func (t *ProtokubeBuilder) ProtokubeEnvironmentVariables() string {
"OS_PASSWORD",
"OS_AUTH_URL",
"OS_REGION_NAME",
"OS_APPLICATION_CREDENTIAL_ID",
"OS_APPLICATION_CREDENTIAL_SECRET",
} {
buffer.WriteString(" --env '")
buffer.WriteString(envVar)
Expand Down
31 changes: 22 additions & 9 deletions pkg/model/bootstrapscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,30 @@ func (b *BootstrapScript) buildEnvironmentVariables(cluster *kops.Cluster) (map[
env["S3_SECRET_ACCESS_KEY"] = os.Getenv("S3_SECRET_ACCESS_KEY")
}

// Pass in required credentials when using user-defined swift endpoint
if os.Getenv("OS_AUTH_URL") != "" {
for _, envVar := range []string{
"OS_TENANT_ID", "OS_TENANT_NAME", "OS_PROJECT_ID", "OS_PROJECT_NAME",
"OS_PROJECT_DOMAIN_NAME", "OS_PROJECT_DOMAIN_ID",
"OS_DOMAIN_NAME", "OS_DOMAIN_ID",
osEnvs := []string{
"OS_TENANT_ID", "OS_TENANT_NAME", "OS_PROJECT_ID", "OS_PROJECT_NAME",
"OS_PROJECT_DOMAIN_NAME", "OS_PROJECT_DOMAIN_ID",
"OS_DOMAIN_NAME", "OS_DOMAIN_ID",
"OS_AUTH_URL",
"OS_REGION_NAME",
}

if os.Getenv("OS_APPLICATION_CREDENTIAL_ID") != "" && os.Getenv("OS_APPLICATION_CREDENTIAL_SECRET") != "" {
osEnvs = append(osEnvs,
"OS_APPLICATION_CREDENTIAL_ID",
"OS_APPLICATION_CREDENTIAL_SECRET",
)
} else {
klog.Warning("exporting username and password. Consider using application credentials instead.")
osEnvs = append(osEnvs,
"OS_USERNAME",
"OS_PASSWORD",
"OS_AUTH_URL",
"OS_REGION_NAME",
} {
)
}

// Pass in required credentials when using user-defined swift endpoint
if os.Getenv("OS_AUTH_URL") != "" {
for _, envVar := range osEnvs {
env[envVar] = fmt.Sprintf("'%s'", os.Getenv(envVar))
}
}
Expand Down
2 changes: 2 additions & 0 deletions util/pkg/env/standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func BuildSystemComponentEnvVars(spec *kops.ClusterSpec) EnvVars {
vars.addEnvVariableIfExist("OS_PASSWORD")
vars.addEnvVariableIfExist("OS_AUTH_URL")
vars.addEnvVariableIfExist("OS_REGION_NAME")
vars.addEnvVariableIfExist("OS_APPLICATION_CREDENTIAL_ID")
vars.addEnvVariableIfExist("OS_APPLICATION_CREDENTIAL_SECRET")

// Digital Ocean related values.
vars.addEnvVariableIfExist("DIGITALOCEAN_ACCESS_TOKEN")
Expand Down
4 changes: 4 additions & 0 deletions util/pkg/vfs/swiftfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ func (oc OpenstackConfig) GetCredential() (gophercloud.AuthOptions, error) {
// fallback to config file
return oc.getCredentialFromFile()
}

if env.ApplicationCredentialID != "" && env.Username == "" {
env.Scope = &gophercloud.AuthScope{}
}
return env, nil

}
Expand Down