-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Forbid ssh key signing with specified extensions when role allowed_extensions is not set #12847
Merged
stevendpclark
merged 3 commits into
main
from
stevendpclark/vault-3375-ssh-extension-fail-close
Oct 15, 2021
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,7 +124,6 @@ SjOQL/GkH1nkRcDS9++aAAAAAmNhAQID | |
|
||
dockerImageTagSupportsRSA1 = "8.1_p1-r0-ls20" | ||
dockerImageTagSupportsNoRSA1 = "8.4_p1-r3-ls48" | ||
|
||
) | ||
|
||
func prepareTestContainer(t *testing.T, tag, caPublicKeyPEM string) (func(), string) { | ||
|
@@ -1414,6 +1413,53 @@ func TestBackend_DefExtTemplatingEnabled(t *testing.T) { | |
} | ||
} | ||
|
||
func TestBackend_EmptyAllowedExtensionFailsClosed(t *testing.T) { | ||
cluster, userpassToken := getSshCaTestCluster(t, testUserName) | ||
defer cluster.Cleanup() | ||
client := cluster.Cores[0].Client | ||
|
||
// Get auth accessor for identity template. | ||
auths, err := client.Sys().ListAuth() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
userpassAccessor := auths["userpass/"].Accessor | ||
|
||
// Write SSH role to test with no allowed extension. We also provide a templated default extension, | ||
// to verify that it's not actually being evaluated | ||
_, err = client.Logical().Write("ssh/roles/test_allow_all_extensions", map[string]interface{}{ | ||
"key_type": "ca", | ||
"allow_user_certificates": true, | ||
"allowed_users": "tuber", | ||
"default_user": "tuber", | ||
"allowed_extensions": "", | ||
"default_extensions_template": false, | ||
"default_extensions": map[string]interface{}{ | ||
"[email protected]": "{{identity.entity.aliases." + userpassAccessor + ".name}}", | ||
}, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Issue SSH certificate with default extensions templating disabled, and user-provided extensions | ||
client.SetToken(userpassToken) | ||
userProvidedAnyExtensionPermissions := map[string]string{ | ||
"[email protected]": "not_userpassname", | ||
} | ||
_, err = client.Logical().Write("ssh/sign/test_allow_all_extensions", map[string]interface{}{ | ||
"public_key": publicKey4096, | ||
"extensions": userProvidedAnyExtensionPermissions, | ||
}) | ||
if err == nil { | ||
t.Fatal("Expected failure we should not have allowed specifying custom extensions") | ||
} | ||
|
||
if !strings.Contains(err.Error(), "are not on allowed list") { | ||
t.Fatalf("Expected failure to contain 'are not on allowed list' but was %s", err) | ||
} | ||
} | ||
|
||
func TestBackend_DefExtTemplatingDisabled(t *testing.T) { | ||
cluster, userpassToken := getSshCaTestCluster(t, testUserName) | ||
defer cluster.Cleanup() | ||
|
@@ -1433,6 +1479,7 @@ func TestBackend_DefExtTemplatingDisabled(t *testing.T) { | |
"allow_user_certificates": true, | ||
"allowed_users": "tuber", | ||
"default_user": "tuber", | ||
"allowed_extensions": "*", | ||
"default_extensions_template": false, | ||
"default_extensions": map[string]interface{}{ | ||
"[email protected]": "{{identity.entity.aliases." + userpassAccessor + ".name}}", | ||
|
@@ -1444,7 +1491,7 @@ func TestBackend_DefExtTemplatingDisabled(t *testing.T) { | |
|
||
sshKeyID := "vault-userpass-"+testUserName+"-9bd0f01b7dfc50a13aa5e5cd11aea19276968755c8f1f9c98965d04147f30ed0" | ||
|
||
// Issue SSH certificate with default extensions templating disabled, and no user-provided extensions | ||
// Issue SSH certificate with default extensions templating disabled, and no user-provided extensions | ||
client.SetToken(userpassToken) | ||
defaultExtensionPermissions := map[string]string{ | ||
"[email protected]": "{{identity.entity.aliases." + userpassAccessor + ".name}}", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
```release-note:breaking-change | ||
secrets/ssh: Roles with empty allowed_extensions will now forbid end-users | ||
specifying extensions when requesting ssh key signing. Update roles setting | ||
allowed_extensions to '*' to permit any extension to be specified by an end-user. | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this has to be a single line, though I'm not positive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's okay as 11775.txt (https://github.com/hashicorp/vault/blob/main/changelog/11775.txt) is multiple lines and seems to have generated ok: https://github.com/hashicorp/vault/blob/main/CHANGELOG.md#180
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good to know.