-
Notifications
You must be signed in to change notification settings - Fork 334
added check if anonymous token policy exists #2790
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
deecdb9
added check if anonymous token policy exists
aahel 8d89601
changed checkIfAnonymousTokenPolicyExists impl
aahel 10946ed
made consts private
aahel 18c2824
added test for configureAnonymousPolicy
aahel 78d17e7
fixed unit test
aahel 525e56b
fixed test and minor refactoring
aahel 977050c
fix typo
aahel 0d4e107
changed some var names
aahel 905e681
added changelog
aahel 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 hidden or 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,3 @@ | ||
| ```release-note:improvement | ||
| control-plane: prevent updation of anonymous-token-policy and anonymous-token if anonymous-token-policy is already attached to the anonymous-token | ||
| ``` |
This file contains hidden or 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
68 changes: 68 additions & 0 deletions
68
control-plane/subcommand/server-acl-init/anonymous_token_test.go
This file contains hidden or 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,68 @@ | ||
| package serveraclinit | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/hashicorp/consul/api" | ||
| "github.com/mitchellh/cli" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func Test_configureAnonymousPolicy(t *testing.T) { | ||
|
|
||
| k8s, testClient := completeSetup(t) | ||
| consulHTTPAddr := testClient.TestServer.HTTPAddr | ||
| consulGRPCAddr := testClient.TestServer.GRPCAddr | ||
|
|
||
| setUpK8sServiceAccount(t, k8s, ns) | ||
| ui := cli.NewMockUi() | ||
| cmd := Command{ | ||
| UI: ui, | ||
| clientset: k8s, | ||
| } | ||
| cmd.init() | ||
| flags := []string{"-connect-inject"} | ||
| cmdArgs := append([]string{ | ||
| "-timeout=1m", | ||
| "-resource-prefix=" + resourcePrefix, | ||
| "-k8s-namespace=" + ns, | ||
| "-auth-method-host=https://my-kube.com", | ||
| "-addresses", strings.Split(consulHTTPAddr, ":")[0], | ||
| "-http-port", strings.Split(consulHTTPAddr, ":")[1], | ||
| "-grpc-port", strings.Split(consulGRPCAddr, ":")[1], | ||
| }, flags...) | ||
| responseCode := cmd.Run(cmdArgs) | ||
| require.Equal(t, 0, responseCode, ui.ErrorWriter.String()) | ||
|
|
||
| bootToken := getBootToken(t, k8s, resourcePrefix, ns) | ||
| consul, err := api.NewClient(&api.Config{ | ||
| Address: consulHTTPAddr, | ||
| Token: bootToken, | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| err = cmd.configureAnonymousPolicy(consul) | ||
| require.NoError(t, err) | ||
|
|
||
| policy, _, err := consul.ACL().PolicyReadByName(anonymousTokenPolicyName, nil) | ||
| require.NoError(t, err) | ||
|
|
||
| testPolicy := api.ACLPolicy{ | ||
| ID: policy.ID, | ||
| Name: anonymousTokenPolicyName, | ||
| Description: "Anonymous token Policy", | ||
| Rules: `acl = "read"`, | ||
| } | ||
| readOnlyPolicy, _, err := consul.ACL().PolicyUpdate(&testPolicy, &api.WriteOptions{}) | ||
| require.NoError(t, err) | ||
|
|
||
| err = cmd.configureAnonymousPolicy(consul) | ||
| require.NoError(t, err) | ||
|
|
||
| actualPolicy, _, err := consul.ACL().PolicyReadByName(anonymousTokenPolicyName, nil) | ||
| require.NoError(t, err) | ||
|
|
||
| // assert policy is still same. | ||
| require.Equal(t, readOnlyPolicy, actualPolicy) | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.