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

Added "Domain" configuration parameter to Swift provider to enable V3 authentication #2554

Merged
merged 3 commits into from
Apr 17, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 16 additions & 5 deletions physical/swift.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,23 @@ func newSwiftBackend(conf map[string]string, logger log.Logger) (Backend, error)
tenant = conf["tenant"]
}

domain := os.Getenv("OS_USER_DOMAIN_NAME")
if domain == "" {
domain = conf["domain"]
}
tenantDomain := os.Getenv("OS_PROJECT_DOMAIN_NAME")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the tenant/project mismatch here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a quirk that the OpenStack project introduced with KeyStone V3. Originally a KeyStone project was called a tenant and that naming was deprecated several releases ago. However, a lot of clients maintain the name "tenant" internally. I kept this name as the underlying "github.com/ncw/swift library still uses the old naming for projects. For the environment variable, I used the name that is required by the most recent versions of the OpenStack CLIs authenticating with KeyStone V3 API as this would present in most users' environments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this is new stuff, it feels like the conf "tenant-domain" should use "project-domain" if the old nomenclature was deprecated several releases ago. Sound reasonable?

if tenantDomain == "" {
tenantDomain = conf["tenant-domain"]
}

c := swift.Connection{
UserName: username,
ApiKey: password,
AuthUrl: authUrl,
Tenant: tenant,
Transport: cleanhttp.DefaultPooledTransport(),
Domain: domain,
UserName: username,
ApiKey: password,
AuthUrl: authUrl,
Tenant: tenant,
TenantDomain: tenantDomain,
Transport: cleanhttp.DefaultPooledTransport(),
}

err := c.Authenticate()
Expand Down
26 changes: 16 additions & 10 deletions physical/swift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ func TestSwiftBackend(t *testing.T) {
password := os.Getenv("OS_PASSWORD")
authUrl := os.Getenv("OS_AUTH_URL")
tenant := os.Getenv("OS_TENANT_NAME")
domain := os.Getenv("OS_USER_DOMAIN_NAME")
tenantDomain := os.Getenv("OS_PROJECT_DOMAIN_NAME")

ts := time.Now().UnixNano()
container := fmt.Sprintf("vault-test-%d", ts)

cleaner := swift.Connection{
UserName: username,
ApiKey: password,
AuthUrl: authUrl,
Tenant: tenant,
Transport: cleanhttp.DefaultPooledTransport(),
Domain: domain,
UserName: username,
ApiKey: password,
AuthUrl: authUrl,
Tenant: tenant,
TenantDomain: tenantDomain,
Transport: cleanhttp.DefaultPooledTransport(),
}

err := cleaner.Authenticate()
Expand Down Expand Up @@ -63,11 +67,13 @@ func TestSwiftBackend(t *testing.T) {
logger := logformat.NewVaultLogger(log.LevelTrace)

b, err := NewBackend("swift", logger, map[string]string{
"username": username,
"password": password,
"container": container,
"auth_url": authUrl,
"tenant": tenant,
"username": username,
"password": password,
"container": container,
"auth_url": authUrl,
"tenant": tenant,
"domain": domain,
"tenant-domain": tenantDomain,
})
if err != nil {
t.Fatalf("err: %s", err)
Expand Down