Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Fix bug with cross namespace policy #505

Merged
merged 12 commits into from
Feb 22, 2023
Merged

Conversation

jm96441n
Copy link
Member

@jm96441n jm96441n commented Feb 10, 2023

Changes proposed in this PR:

When new namespace is created we should automatically apply the cross-namespace-policy policy to the newly created namespace to ensure cross namespace communication is allowed.

Fixes #510

How I've tested this PR:

  • Clone the files from the following gist: https://gist.github.com/jm96441n/7e005c82fa918b7b73c11abb617b4998
  • Replace the <YOUR ENTERPRISE KEY> with a key for enterprise consul in the deploy.sh file
  • From the api-gw repo run make docker/dev on the main branch (without these changes)
  • Run the deploy.sh script
  • After that finishes from the terminal run curl 0:30602 -vv --header 'Host: nginx.green.daskt.nsbug.it' and you should see a 503 error along with no healthy upstream
  • In the consul UI if you select Manage Namespaces from the Namespaces drop down you will see the green namespace does not have the cross-namespace-policy attached to it
  • In the api-gateway repo checkout this branch and run make docker/dev again to build the image with the changes from this branch
  • Run the reload.sh script from the gist
  • After that finishes from the terminal run curl 0:30602 -vv --header 'Host: nginx.green.daskt.nsbug.it' and you should see a response with a bunch of html (you may see a "connection reset by peer" error, if so give things a few seconds to reconcile and try again)
  • In the consul UI if you select Manage Namespaces from the Namespaces drop down you will see the green namespace now has the cross-namespace-policy attached to it

How I expect reviewers to test this PR:

Code Review
Can run the above steps

Checklist:

  • Tests added
  • CHANGELOG entry added

    Run make changelog-entry for guidance in authoring a changelog entry, and
    commit the resulting file, which should have a name matching your PR number.
    Entries should use imperative present tense (e.g. Add support for...)

@jm96441n jm96441n changed the title jFix bug with cross namespace policy Fix bug with cross namespace policy Feb 10, 2023
@jm96441n jm96441n added the type/bug Something isn't working label Feb 10, 2023
@jm96441n jm96441n force-pushed the fix-bug-with-cross-namespace-policy branch 2 times, most recently from 546e97d to c7a7de6 Compare February 16, 2023 18:58
Copy link
Contributor

@andrewstucki andrewstucki left a comment

Choose a reason for hiding this comment

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

Overall looks decent to me, two quick questions:

  1. About the way we're adding flags, see below, and
  2. About whether or not we want to handle patching existing namespaces with this additional policy

// If not, create it.
var aclConfig capi.NamespaceACLConfig
// If the namespace does not, create it with default cross-namespace-policy.
crossNamespacePolicy, err := getOrCreateCrossNamespacePolicy(client, partitionInfo)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to update an existing namespace with the policy in case it was created without? I'm thinking probably not since users could create the namespace themselves with a different set of policies that still allow for cross-namespace service resolution and maybe some other stuff they're interested in.

But, if we do I think we'll probably need to do something like append this policy onto an existing namespace and then CAS the namespace if the policy wasn't previously there.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah I don't think we want to patch existing namespaces for that reason you mentioned: they're not managed by us and might give broader permissions than the operator wants (it could be a bit of a footgun, but if the operator is manually creating namespaces I'd expect them to also be managing the permissions)

internal/commands/server/command.go Outdated Show resolved Hide resolved
internal/consul/namespaces.go Show resolved Hide resolved
Copy link
Contributor

@andrewstucki andrewstucki left a comment

Choose a reason for hiding this comment

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

We'll want to make a corresponding change in the Helm chart to set the environment variables. Feel free to link it back here.

@jm96441n
Copy link
Member Author

jm96441n commented Feb 17, 2023

so @andrewstucki it looks like there might already be an env variable in the helm chart to handle that (should've checked their there first) https://github.com/hashicorp/consul-k8s/blob/main/charts/consul/templates/api-gateway-controller-deployment.yaml#L119
going to update this PR to use that

@jm96441n jm96441n force-pushed the fix-bug-with-cross-namespace-policy branch from ec8ba84 to 5495997 Compare February 21, 2023 17:13
@jm96441n jm96441n merged commit f78ec58 into main Feb 22, 2023
@jm96441n jm96441n deleted the fix-bug-with-cross-namespace-policy branch February 22, 2023 15:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API Gateway doesn't attach cross-namespace lookup policy on namespace creation
2 participants