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

Add read support to sys/auth/:path #12793

Merged
merged 2 commits into from
Jan 25, 2022
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
3 changes: 3 additions & 0 deletions changelog/12793.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note: feature
auth: reading `sys/auth/:path` now returns the configuration for the auth engine mounted at the given path
```
34 changes: 34 additions & 0 deletions vault/logical_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -1875,6 +1875,40 @@ func (b *SystemBackend) handleAuthTable(ctx context.Context, req *logical.Reques
return resp, nil
}

func (b *SystemBackend) handleReadAuth(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
path := data.Get("path").(string)
path = sanitizePath(path)

ns, err := namespace.FromContext(ctx)
if err != nil {
return nil, err
}

b.Core.authLock.RLock()
defer b.Core.authLock.RUnlock()

for _, entry := range b.Core.auth.Entries {
// Only show entry for current namespace
if entry.Namespace().Path != ns.Path || entry.Path != path{
continue
}

cont, err := b.Core.checkReplicatedFiltering(ctx, entry, credentialRoutePrefix)
if err != nil {
return nil, err
}
if cont {
continue
}

return &logical.Response{
Data: mountInfo(entry),
}, nil
}

return logical.ErrorResponse("No auth engine at %s", path), nil
}

func expandStringValsWithCommas(configMap map[string]interface{}) error {
configParamNameSlice := []string{
"audit_non_hmac_request_keys",
Expand Down
4 changes: 4 additions & 0 deletions vault/logical_system_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,10 @@ func (b *SystemBackend) authPaths() []*framework.Path {
},
},
Operations: map[logical.Operation]framework.OperationHandler{
logical.ReadOperation: &framework.PathOperation{
Callback: b.handleReadAuth,
Summary: "Read the configuration of the auth engine at the given path.",
},
logical.UpdateOperation: &framework.PathOperation{
Callback: b.handleEnableAuth,
Summary: "Enables a new auth method.",
Expand Down
9 changes: 9 additions & 0 deletions vault/logical_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,15 @@ func TestSystemBackend_authTable(t *testing.T) {
if diff := deep.Equal(resp.Data, exp); diff != nil {
t.Fatal(diff)
}

req = logical.TestRequest(t, logical.ReadOperation, "auth/token")
resp, err = b.HandleRequest(namespace.RootContext(nil), req)
if err != nil {
t.Fatalf("err: %v", err)
}
if diff := deep.Equal(resp.Data, exp["token/"]); diff != nil {
t.Fatal(diff)
}
}

func TestSystemBackend_enableAuth(t *testing.T) {
Expand Down
61 changes: 61 additions & 0 deletions website/content/api-docs/system/auth.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,67 @@ $ curl \
http://127.0.0.1:8200/v1/sys/auth/my-auth
```

## Read Auth Method configuration

This endpoints returns the configuration of the auth method at the given path.

| Method | Path |
| :----- | :--------------- |
| `GET` | `/sys/auth/path` |

### Sample Request

```shell-session
$ curl \
--header "X-Vault-Token: ..." \
http://127.0.0.1:8200/v1/sys/auth/my-auth
```

### Sample Response

```json
{
"uuid": "4b42d1a4-0a0d-3c88-ae90-997e0c8b41be",
"type": "github",
"accessor": "auth_github_badd7fd0",
"local": false,
"seal_wrap": false,
"external_entropy_access": false,
"options": null,
"config": {
"default_lease_ttl": 0,
"force_no_cache": false,
"max_lease_ttl": 0,
"token_type": "default-service"
},
"description": "",
"request_id": "8d2a1e33-4c00-46a5-f50d-4dc5f5d96f12",
"lease_id": "",
"renewable": false,
"lease_duration": 0,
"data": {
"accessor": "auth_github_badd7fd0",
"config": {
"default_lease_ttl": 0,
"force_no_cache": false,
"max_lease_ttl": 0,
"token_type": "default-service"
},
"description": "",
"external_entropy_access": false,
"local": false,
"options": null,
"seal_wrap": false,
"type": "github",
"uuid": "4b42d1a4-0a0d-3c88-ae90-997e0c8b41be"
},
"wrap_info": null,
"warnings": null,
"auth": null
}
```


## Disable Auth Method

This endpoint disables the auth method at the given auth path.
Expand Down