Skip to content

Commit af43e99

Browse files
authored
Add project/domain in root_token and remove password from cloud response (#84)
Add `project`/`domain` in `root_token` and remove `password` from `cloud` response Description Remove password from cloud response Add project_name/id and domain_name/id in token root token reponse Acceptance tests Running acceptance tests... === RUN TestPlugin === RUN TestPlugin/TestCloudLifecycle === RUN TestPlugin/TestCloudLifecycle/WriteCloud === RUN TestPlugin/TestCloudLifecycle/ReadCloud === RUN TestPlugin/TestCloudLifecycle/ListClouds === RUN TestPlugin/TestCloudLifecycle/ListClouds/method-LIST === PAUSE TestPlugin/TestCloudLifecycle/ListClouds/method-LIST === RUN TestPlugin/TestCloudLifecycle/ListClouds/method-GET === PAUSE TestPlugin/TestCloudLifecycle/ListClouds/method-GET === CONT TestPlugin/TestCloudLifecycle/ListClouds/method-LIST === CONT TestPlugin/TestCloudLifecycle/ListClouds/method-GET === RUN TestPlugin/TestCloudLifecycle/DeleteCloud === RUN TestPlugin/TestCredsLifecycle === RUN TestPlugin/TestCredsLifecycle/user_password === RUN TestPlugin/TestCredsLifecycle/root_token === RUN TestPlugin/TestCredsLifecycle/user_token === RUN TestPlugin/TestInfo === RUN TestPlugin/TestRoleLifecycle roles_test.go:53: Cloud with name `y96wtu4gft` was created === RUN TestPlugin/TestRoleLifecycle/WriteRole === RUN TestPlugin/TestRoleLifecycle/ReadRole === RUN TestPlugin/TestRoleLifecycle/ListRoles === RUN TestPlugin/TestRoleLifecycle/ListRoles/method-LIST === PAUSE TestPlugin/TestRoleLifecycle/ListRoles/method-LIST === RUN TestPlugin/TestRoleLifecycle/ListRoles/method-GET === PAUSE TestPlugin/TestRoleLifecycle/ListRoles/method-GET === CONT TestPlugin/TestRoleLifecycle/ListRoles/method-LIST === CONT TestPlugin/TestRoleLifecycle/ListRoles/method-GET === RUN TestPlugin/TestRoleLifecycle/DeleteRole === CONT TestPlugin/TestRoleLifecycle plugin_test.go:337: Cloud with name `y96wtu4gft` has been removed === RUN TestPlugin/TestRootRotate rotate_test.go:65: Cloud with name `default1` was created rotate_test.go:68: Cloud with name `saf4` was created plugin_test.go:337: Cloud with name `saf4` has been removed plugin_test.go:337: Cloud with name `default1` has been removed --- PASS: TestPlugin (11.48s) --- PASS: TestPlugin/TestCloudLifecycle (0.39s) --- PASS: TestPlugin/TestCloudLifecycle/WriteCloud (0.38s) --- PASS: TestPlugin/TestCloudLifecycle/ReadCloud (0.00s) --- PASS: TestPlugin/TestCloudLifecycle/ListClouds (0.00s) --- PASS: TestPlugin/TestCloudLifecycle/ListClouds/method-LIST (0.00s) --- PASS: TestPlugin/TestCloudLifecycle/ListClouds/method-GET (0.01s) --- PASS: TestPlugin/TestCloudLifecycle/DeleteCloud (0.00s) --- PASS: TestPlugin/TestCredsLifecycle (4.83s) --- PASS: TestPlugin/TestCredsLifecycle/user_password (1.38s) --- PASS: TestPlugin/TestCredsLifecycle/root_token (0.66s) --- PASS: TestPlugin/TestCredsLifecycle/user_token (1.90s) --- PASS: TestPlugin/TestInfo (0.00s) --- PASS: TestPlugin/TestRoleLifecycle (0.02s) --- PASS: TestPlugin/TestRoleLifecycle/WriteRole (0.00s) --- PASS: TestPlugin/TestRoleLifecycle/ReadRole (0.00s) --- PASS: TestPlugin/TestRoleLifecycle/ListRoles (0.00s) --- PASS: TestPlugin/TestRoleLifecycle/ListRoles/method-LIST (0.00s) --- PASS: TestPlugin/TestRoleLifecycle/ListRoles/method-GET (0.00s) --- PASS: TestPlugin/TestRoleLifecycle/DeleteRole (0.00s) --- PASS: TestPlugin/TestRootRotate (4.43s) PASS ok github.com/opentelekomcloud/vault-plugin-secrets-openstack/acceptance 11.490s Reviewed-by: Anton Sidelnikov <None>
1 parent 358dea9 commit af43e99

File tree

6 files changed

+63
-35
lines changed

6 files changed

+63
-35
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,20 @@ You must have a Vault server already running, unsealed, and authenticated.
8080

8181
```sh
8282
$ vault read /openstack/creds/example-role
83-
83+
8484
Key Value
8585
--- -----
86-
lease_id openstack/creds/example-role/Kuma41Qu8s1k5f4AZ8PUmDxE
87-
lease_duration 1h
86+
lease_id openstack/creds/example-role/v7I5mxix3iCpkdGYDelNmKdo
87+
lease_duration 24h
8888
lease_renewable false
89-
auth_url https://127.0.0.1/v3/
90-
expires_at 2022-04-19 02:03:36 +0000 UTC
91-
token gAAAAABiXW-4r2Ofy4s4-oFlnbNgIrqONkmIHPnE...
89+
auth map[auth_url:https://127.0.0.1/v3/ project_domain_name:mydomain project_name:myproject token:MIIF-QYJKoZIhvcNAQcCoIIF7jCCBeoCAQExDTALBglghkgBZQMEAgEwggOCBgkqhkiG9w0BBwGgggNzBIIDb3sidG
90+
9rZW4iOnsiZXhwaXJlc19hdCI6IjIwMjItMDUtMjRUMTc6MTU6NDQuNTI4MDAwWiIsIm1ldGhvZHMiOlsicGFzc3dvcmQiXSwiY2F0YWxvZyI6W10sInJvbGVzIjpbeyJuYW1lIjoic2VydmVyX2FkbSIsImlkIjoiMCJ9LHsibmFtZSI6InRlX2FkbWluIiwiaWQiOiIwIn0seyJuYW1lIjoib3BfZ2F0ZWRfY2
91+
NlX3N3aXRjaCIsImlkIjoiMCJ9LHsibmFtZSIwiaWQiOiIwIn1dLCJwcm9qZWN0Ijp7ImRvbWFpbiI6eyJ4ZG9tYWluX3R5cGUiOiJUU0kiLCJuYW1lIjoiT1RDMDAwMDAwMDAwMDEwMDAwMDA0NDciLCJpZCI6ImZhZjcyZTg1MWMxZTQ4MzE5Mjk2ZjE4MTgxOGYxNzZhIiwieGRvbWFpbl9pZCI6IjAwMD
92+
AwMDAwMDAxMDAwMDAwNDQ3In0sIm5hbWUiOiJlCwYDVQQHDARCb25uMRwwGgYDVQQKDBNEZXV0c2NoZSBUZWxla29tIEFHMTcwNQYDVQQLDC5ULVN5c3RlbXMgUFUgUHVibGljIENsb3VkIC0gT3BlbiBUZWxla29tIENsb3VkMRMwEQYDVQQDDApjYS5pYW0ucGtpAg
93+
kAi0NlULiz2iIwCwYJYIZIAWUDBAIBMA0GCSqGSIb3DQEBAQUABIIBgBtmvHm0ChAl0kppzoaVJgYSovI0ujP6Srk7sDrDVO7auks+dQ-D1yb4Xh398mn1VNs0i4e98Bp-AQnwb3N-uZcUnbNHAUg2uRUoWUBmVs8oXszkGJYRK6Kf+BgGE5GqS4KgE2e8ob96xPGRQ5WdKMjYzb9nAz37sUsvy-jz70anyhKoWW
94+
B55kYVDyCn4JYh7-ivKrfaHdNY9GSebskw0zqAeMr2Lr4DZyZcr6mor88p1MnT+kz028qcxkrHBKiHQ0wt8YWUfAFD7RV-b97ZkBBSeEMs3ai1zMbYWXtIzztAWZLn52l+vstKiae8hXoE4HIpkMOD+fTyj2z6gN7X6xfvfBIZC2mSOQ2PAiTls2JTrcDVEo3eCI1vgvKrFdY52yDGmb3lHBITPPya0ztvjFrdNv59Gdx8-rxf1fr1htXRhyaMOBiaPDGVkUtjwqC9Zjm3fve5Z5A6UQurBm8xDjtRWjnFB5kAQ708adpCUHJAdxand3Mf-Md4UysLVSf4Ug==]
95+
auth_type token
96+
9297
```
9398

9499
### Developing

acceptance/cloud_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ func (p *PluginTest) TestCloudLifecycle() {
7070
AuthURL: data["auth_url"].(string),
7171
UserDomainName: data["user_domain_name"].(string),
7272
Username: data["username"].(string),
73-
Password: data["password"].(string),
7473
UsernameTemplate: openstack.DefaultUsernameTemplate,
7574
PasswordPolicy: data["password_policy"].(string),
7675
}

doc/source/api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ $ curl \
7575
{
7676
"auth_url": "https://example.com/v3/",
7777
"username": "admin",
78-
"user_domain_name": "Default"
78+
"user_domain_name": "Default",
79+
"username_template": "user-{{ .RoleName }}-{{ random 4 }}"
7980
}
8081
```
8182

openstack/path_cloud.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ func (b *backend) pathCloudRead(ctx context.Context, r *logical.Request, d *fram
210210
"auth_url": cloudConfig.AuthURL,
211211
"user_domain_name": cloudConfig.UserDomainName,
212212
"username": cloudConfig.Username,
213-
"password": cloudConfig.Password,
214213
"username_template": cloudConfig.UsernameTemplate,
215214
"password_policy": cloudConfig.PasswordPolicy,
216215
},

openstack/path_cloud_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ func TestCloudCreate(t *testing.T) {
143143
assert.Equal(t, res.Data["auth_url"], testAuthURL)
144144
assert.Equal(t, res.Data["user_domain_name"], testUserDomainName)
145145
assert.Equal(t, res.Data["username"], testUsername)
146-
assert.Equal(t, res.Data["password"], testPassword1)
147146
})
148147

149148
t.Run("Delete", func(t *testing.T) {

openstack/path_creds.go

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,17 @@ func getRootCredentials(client *gophercloud.ServiceClient, opts *credsOpts) (*lo
105105
return nil, err
106106
}
107107

108+
authResponse := &authResponseData{
109+
AuthURL: opts.Config.AuthURL,
110+
Token: token.ID,
111+
DomainName: opts.Config.UserDomainName,
112+
}
113+
108114
data := map[string]interface{}{
109-
"auth": map[string]interface{}{
110-
"auth_url": opts.Config.AuthURL,
111-
"token": token.ID,
112-
"user_domain_name": opts.Config.UserDomainName,
113-
},
115+
"auth": formAuthResponse(
116+
opts.Role,
117+
authResponse,
118+
),
114119
"auth_type": "token",
115120
}
116121
secret := &logical.Secret{
@@ -159,14 +164,16 @@ func getTmpUserCredentials(client *gophercloud.ServiceClient, opts *credsOpts) (
159164
return nil, err
160165
}
161166

167+
authResponse := &authResponseData{
168+
AuthURL: opts.Config.AuthURL,
169+
Token: token.ID,
170+
DomainID: user.DomainID,
171+
}
172+
162173
data = map[string]interface{}{
163174
"auth": formAuthResponse(
164175
opts.Role,
165-
"",
166-
"",
167-
token.ID,
168-
opts.Config.AuthURL,
169-
user.DomainID,
176+
authResponse,
170177
),
171178
"auth_type": "token",
172179
}
@@ -177,14 +184,16 @@ func getTmpUserCredentials(client *gophercloud.ServiceClient, opts *credsOpts) (
177184
"expires_at": token.ExpiresAt.String(),
178185
}
179186
case SecretPassword:
187+
authResponse := &authResponseData{
188+
AuthURL: opts.Config.AuthURL,
189+
Username: user.Name,
190+
Password: password,
191+
DomainID: user.DomainID,
192+
}
180193
data = map[string]interface{}{
181194
"auth": formAuthResponse(
182195
opts.Role,
183-
user.Name,
184-
password,
185-
"",
186-
opts.Config.AuthURL,
187-
user.DomainID,
196+
authResponse,
188197
),
189198
"auth_type": "password",
190199
}
@@ -465,7 +474,16 @@ func getScopeFromRole(role *roleEntry) tokens.Scope {
465474
return scope
466475
}
467476

468-
func formAuthResponse(role *roleEntry, username, password, token, authURL, domainID string) map[string]interface{} {
477+
type authResponseData struct {
478+
AuthURL string
479+
Username string
480+
Password string
481+
Token string
482+
DomainID string
483+
DomainName string
484+
}
485+
486+
func formAuthResponse(role *roleEntry, authResponse *authResponseData) map[string]interface{} {
469487
var auth map[string]interface{}
470488

471489
switch {
@@ -474,24 +492,31 @@ func formAuthResponse(role *roleEntry, username, password, token, authURL, domai
474492
"project_id": role.ProjectID,
475493
}
476494
case role.ProjectName != "":
477-
auth = map[string]interface{}{
478-
"project_name": role.ProjectName,
479-
"project_domain_id": domainID,
495+
if role.Root {
496+
auth = map[string]interface{}{
497+
"project_name": role.ProjectName,
498+
"project_domain_name": authResponse.DomainName,
499+
}
500+
} else {
501+
auth = map[string]interface{}{
502+
"project_name": role.ProjectName,
503+
"project_domain_id": authResponse.DomainID,
504+
}
480505
}
481506
default:
482507
auth = map[string]interface{}{
483-
"user_domain_id": domainID,
508+
"user_domain_id": authResponse.DomainID,
484509
}
485510
}
486511

487-
if token != "" {
488-
auth["token"] = token
512+
if authResponse.Token != "" {
513+
auth["token"] = authResponse.Token
489514
} else {
490-
auth["username"] = username
491-
auth["password"] = password
515+
auth["username"] = authResponse.Username
516+
auth["password"] = authResponse.Password
492517
}
493518

494-
auth["auth_url"] = authURL
519+
auth["auth_url"] = authResponse.AuthURL
495520

496521
return auth
497522
}

0 commit comments

Comments
 (0)