Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Get individual namespaces when given whitelist #1298

Merged
merged 3 commits into from
Aug 23, 2018
Merged

Conversation

squaremo
Copy link
Member

Asking for the full list of namespaces requires a cluster-scoped permission of listing namespaces; however, a common scenario for using the whitelist is that you want to restrict permissions.

If we simply Get the whitelisted namespaces, ignoring those we're forbidden to see (or that don't exist, as before), we don't need the cluster-scoped permission and can just be given permissions per namespace.

The trade is that we do an API request per whitelisted namespace. I expect there to be relatively few, though, so I don't think this is a huge deal.

@squaremo squaremo force-pushed the dont-require-list-ns branch from abaa1b6 to c5bfdd1 Compare August 21, 2018 14:45
@squaremo
Copy link
Member Author

/cc @justinbarrick @mwhittington21

Asking for the full list of namespaces requires a cluster-scoped
permission of listing namespaces; however, a common scenario for using
the whitelist is that you want to restrict permissions.

If we simply Get the whitelisted namespaces, ignoring those we're
forbidden to see (or that don't exist, as before), we don't need the
cluster-scoped permission and can just be given permissions per
namespace.

The trade is that we do an API request per whitelisted namespace. I
expect there to be relatively few, though, so I don't think this is a
huge deal.
@squaremo squaremo force-pushed the dont-require-list-ns branch from c5bfdd1 to 9b7aee1 Compare August 21, 2018 14:48
@petervandenabeele
Copy link
Contributor

petervandenabeele commented Aug 21, 2018

I presume this would be part of a fix for the question I raised recently:
https://weave-community.slack.com/archives/C2ND76PAA/p1534778698000100
(the other part being to use an explicit whitelist of namespaces).

@squaremo
Copy link
Member Author

squaremo commented Aug 21, 2018

I presume this would be part of a fix for the question I raised recently:
https://weave-community.slack.com/messages/C2ND76PAA/convo/C2ND76PAA-1534779886.000100/
(the other part being to use an explicit whitelist of namespaces).

This changes how whitelisting is implemented, so you need to give flux slightly fewer permissions. I'll do a follow-up that documents exactly what you do need, but with this PR, it should be a little as:

  • A role that can patch the SSH key secret in flux's namespace (if you don't populate it yourself)
  • A role that can list, get, create and update resources you want managed, for each namespace in the whitelist

@oliviabarrick
Copy link
Contributor

Awesome!

for _, name := range c.nsWhitelist {
if ns, err := c.client.CoreV1().Namespaces().Get(name, meta_v1.GetOptions{}); err == nil {
nsList = append(nsList, *ns)
} else if !(apierrors.IsNotFound(err) || apierrors.IsUnauthorized(err) || apierrors.IsForbidden(err)) {

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

@squaremo squaremo force-pushed the dont-require-list-ns branch from d0a846e to 8600d06 Compare August 22, 2018 13:37
@oliviabarrick
Copy link
Contributor

If you wanted to avoid spamming the logs you could cache in memory which namespaces you have logged errors for and rate limit it.

@squaremo squaremo requested a review from rade August 23, 2018 10:37
Copy link
Contributor

@rade rade left a comment

Choose a reason for hiding this comment

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

I really think we should log the actual ns access failure reasons. But it's not a blocker.

nsList = append(nsList, *ns)
case apierrors.IsUnauthorized(err) || apierrors.IsForbidden(err) || apierrors.IsNotFound(err):
if !c.nsWhitelistLogged[name] {
c.logger.Log("warning", "whitelisted namespace unauthorized, forbidden, or not found", "namespace", name)

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

If we log a warning every time a whitelisted is missing, there may be
an awful lot of repeated warnings. Instead, keep track of which
namespaces have been seen to be missing (resetting when they are seen
again), and log only when the namespace was not known to be missing.
@squaremo squaremo force-pushed the dont-require-list-ns branch from 2e9ad51 to 2302abf Compare August 23, 2018 11:54
@squaremo squaremo merged commit 4269545 into master Aug 23, 2018
@squaremo squaremo deleted the dont-require-list-ns branch August 23, 2018 11:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants