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

Enable access to Openstack via application credentials #277

Merged
merged 3 commits into from
Apr 20, 2023
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
15 changes: 15 additions & 0 deletions pkg/cmd/env/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,21 @@ func execTmpl(o *options, shoot *gardencorev1beta1.Shoot, secret *corev1.Secret,
}

data["authURL"] = authURL

_, ok := data["applicationCredentialSecret"]
if ok {
data["authType"] = "v3applicationcredential"
data["authStrategy"] = ""
data["tenantName"] = ""
data["username"] = ""
data["password"] = ""
} else {
data["authStrategy"] = "keystone"
data["authType"] = ""
data["applicationCredentialID"] = ""
data["applicationCredentialName"] = ""
data["applicationCredentialSecret"] = ""
}
}

filename := filepath.Join(o.GardenDir, "templates", o.ProviderType+".tmpl")
Expand Down
72 changes: 42 additions & 30 deletions pkg/cmd/env/templates/openstack.tmpl
Original file line number Diff line number Diff line change
@@ -1,75 +1,87 @@
{{define "default"}}{{if .__meta.unset -}}
unset OS_IDENTITY_API_VERSION;
unset OS_AUTH_VERSION;
unset OS_AUTH_STRATEGY;
unset OS_AUTH_URL;
unset OS_TENANT_NAME;
unset OS_PROJECT_DOMAIN_NAME;
unset OS_USER_DOMAIN_NAME;
unset OS_REGION_NAME;
unset OS_AUTH_STRATEGY;
unset OS_TENANT_NAME;
unset OS_USERNAME;
unset OS_PASSWORD;
unset OS_REGION_NAME;
unset OS_AUTH_TYPE;
unset OS_APPLICATION_CREDENTIAL_ID;
unset OS_APPLICATION_CREDENTIAL_NAME;
unset OS_APPLICATION_CREDENTIAL_SECRET;
{{else -}}
export OS_IDENTITY_API_VERSION='3';
export OS_AUTH_VERSION='3';
export OS_AUTH_STRATEGY='keystone';
export OS_AUTH_URL={{.authURL | shellEscape}};
export OS_TENANT_NAME={{.tenantName | shellEscape}};
export OS_PROJECT_DOMAIN_NAME={{.domainName | shellEscape}};
export OS_USER_DOMAIN_NAME={{.domainName | shellEscape}};
export OS_REGION_NAME={{.region | shellEscape}};
export OS_AUTH_STRATEGY={{.authStrategy | shellEscape}};
export OS_TENANT_NAME={{.tenantName | shellEscape}};
export OS_USERNAME={{.username | shellEscape}};
export OS_PASSWORD={{.password | shellEscape}};
export OS_REGION_NAME={{.region | shellEscape}};
export OS_AUTH_TYPE={{.authType | shellEscape}};
export OS_APPLICATION_CREDENTIAL_ID={{.applicationCredentialID | shellEscape}};
export OS_APPLICATION_CREDENTIAL_NAME={{.applicationCredentialName | shellEscape}};
export OS_APPLICATION_CREDENTIAL_SECRET={{.applicationCredentialSecret | shellEscape}};
{{end}}{{template "usage-hint" .__meta}}{{end}}

{{define "bash"}}{{template "default" .}}{{end}}
{{define "zsh"}}{{template "default" .}}{{end}}

{{define "fish"}}{{if .__meta.unset -}}
set -e OS_IDENTITY_API_VERSION;
set -e OS_AUTH_VERSION;
set -e OS_AUTH_STRATEGY;
set -e OS_AUTH_URL;
set -e OS_TENANT_NAME;
set -e OS_PROJECT_DOMAIN_NAME;
set -e OS_USER_DOMAIN_NAME;
set -e OS_REGION_NAME;
set -e OS_AUTH_STRATEGY;
set -e OS_TENANT_NAME;
set -e OS_USERNAME;
set -e OS_PASSWORD;
set -e OS_REGION_NAME;
set -e OS_AUTH_TYPE;
set -e OS_APPLICATION_CREDENTIAL_ID;
set -e OS_APPLICATION_CREDENTIAL_NAME;
set -e OS_APPLICATION_CREDENTIAL_SECRET;
{{else -}}
set -gx OS_IDENTITY_API_VERSION '3';
set -gx OS_AUTH_VERSION '3';
set -gx OS_AUTH_STRATEGY 'keystone';
set -gx OS_AUTH_URL {{.authURL | shellEscape}};
set -gx OS_TENANT_NAME {{.tenantName | shellEscape}};
set -gx OS_PROJECT_DOMAIN_NAME {{.domainName | shellEscape}};
set -gx OS_USER_DOMAIN_NAME {{.domainName | shellEscape}};
set -gx OS_REGION_NAME {{.region | shellEscape}};
set -gx OS_AUTH_STRATEGY {{.authStrategy | shellEscape}};
set -gx OS_TENANT_NAME {{.tenantName | shellEscape}};
set -gx OS_USERNAME {{.username | shellEscape}};
set -gx OS_PASSWORD {{.password | shellEscape}};
set -gx OS_REGION_NAME {{.region | shellEscape}};
set -gx OS_AUTH_TYPE {{.authType | shellEscape}};
set -gx OS_APPLICATION_CREDENTIAL_ID {{.applicationCredentialID | shellEscape}};
set -gx OS_APPLICATION_CREDENTIAL_NAME {{.applicationCredentialName | shellEscape}};
set -gx OS_APPLICATION_CREDENTIAL_SECRET {{.applicationCredentialSecret | shellEscape}};
{{end}}{{template "usage-hint" .__meta}}{{end}}

{{define "powershell"}}{{if .__meta.unset -}}
Remove-Item -ErrorAction SilentlyContinue Env:\OS_IDENTITY_API_VERSION;
Remove-Item -ErrorAction SilentlyContinue Env:\OS_AUTH_VERSION;
Remove-Item -ErrorAction SilentlyContinue Env:\OS_AUTH_STRATEGY;
Remove-Item -ErrorAction SilentlyContinue Env:\OS_AUTH_URL;
Remove-Item -ErrorAction SilentlyContinue Env:\OS_TENANT_NAME;
Remove-Item -ErrorAction SilentlyContinue Env:\OS_PROJECT_DOMAIN_NAME;
Remove-Item -ErrorAction SilentlyContinue Env:\OS_USER_DOMAIN_NAME;
Remove-Item -ErrorAction SilentlyContinue Env:\OS_REGION_NAME;
Remove-Item -ErrorAction SilentlyContinue Env:\OS_AUTH_STRATEGY;
Remove-Item -ErrorAction SilentlyContinue Env:\OS_TENANT_NAME;
Remove-Item -ErrorAction SilentlyContinue Env:\OS_USERNAME;
Remove-Item -ErrorAction SilentlyContinue Env:\OS_PASSWORD;
Remove-Item -ErrorAction SilentlyContinue Env:\OS_REGION_NAME;
Remove-Item -ErrorAction SilentlyContinue Env:\OS_AUTH_TYPE;
Remove-Item -ErrorAction SilentlyContinue Env:\OS_APPLICATION_CREDENTIAL_ID;
Remove-Item -ErrorAction SilentlyContinue Env:\OS_APPLICATION_CREDENTIAL_NAME;
Remove-Item -ErrorAction SilentlyContinue Env:\OS_APPLICATION_CREDENTIAL_SECRET;
{{else -}}
$Env:OS_IDENTITY_API_VERSION = '3';
$Env:OS_AUTH_VERSION = '3';
$Env:OS_AUTH_STRATEGY = 'keystone';
$Env:OS_AUTH_URL = {{.authURL | shellEscape}};
$Env:OS_TENANT_NAME = {{.tenantName | shellEscape}};
$Env:OS_PROJECT_DOMAIN_NAME = {{.domainName | shellEscape}};
$Env:OS_USER_DOMAIN_NAME = {{.domainName | shellEscape}};
$Env:OS_REGION_NAME = {{.region | shellEscape}};
$Env:OS_AUTH_STRATEGY = {{.authStrategy | shellEscape}};
$Env:OS_TENANT_NAME = {{.tenantName | shellEscape}};
$Env:OS_USERNAME = {{.username | shellEscape}};
$Env:OS_PASSWORD = {{.password | shellEscape}};
$Env:OS_REGION_NAME = {{.region | shellEscape}};
$Env:OS_AUTH_TYPE = {{.authType | shellEscape}};
$Env:OS_APPLICATION_CREDENTIAL_ID = {{.applicationCredentialID | shellEscape}};
$Env:OS_APPLICATION_CREDENTIAL_NAME = {{.applicationCredentialName | shellEscape}};
$Env:OS_APPLICATION_CREDENTIAL_SECRET = {{.applicationCredentialSecret | shellEscape}};
{{end}}{{template "usage-hint" .__meta}}{{end}}

12 changes: 7 additions & 5 deletions pkg/cmd/env/testdata/openstack/export.bash
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
export OS_IDENTITY_API_VERSION='3';
export OS_AUTH_VERSION='3';
export OS_AUTH_STRATEGY='keystone';
export OS_AUTH_URL='keyStoneURL';
export OS_TENANT_NAME='tenant';
export OS_PROJECT_DOMAIN_NAME='domain';
export OS_USER_DOMAIN_NAME='domain';
export OS_REGION_NAME='europe';
export OS_AUTH_STRATEGY='keystone';
export OS_TENANT_NAME='tenant';
export OS_USERNAME='user';
export OS_PASSWORD='secret';
export OS_REGION_NAME='europe';
export OS_AUTH_TYPE='';
export OS_APPLICATION_CREDENTIAL_ID='';
export OS_APPLICATION_CREDENTIAL_NAME='';
export OS_APPLICATION_CREDENTIAL_SECRET='';

# Run this command to configure openstack for your shell:
# eval $(gardenctl provider-env bash)