Skip to content

Conversation

@jaypipes
Copy link
Collaborator

In order to allow the ClusterRole associated with the ServiceAccount of
a controller started in Cluster Mode to require Read/List/Watch
permissions on Secrets in ALL Kubernetes Namespaces, we need to change
the way that Secret values are read in the resource reconciler.

When a "normal" client-go Kubernetes client is created and a single
watch namespace is not provided, then whenever that client is used to
read object information, a new SharedInformer cache is created for that
Kind of resource across all Namespaces.

This SharedInformer cache sets up listers and watchers on all resources
of that Kind of resource across all Namespaces and thus the ClusterRole
associated with the ServiceAccount of the controller needs permissions
to get, list and watch those resources across all Namespaces.

For Secret resources, this permission to list/watch Secrets across all
Namespaces is too broad for many security-conscious organizations. For
these organizations, they wish to restrict the ACK controller to only
watch Secret resources that are in specific Namespaces that the ACK
custom resources are created in.

In order to fulfill this security requirement, we needed to make a
relatively small change to the resource reconciler's
SecretValueFromReference method to use the non-caching apiReader part of
the Kubernetes client.

The other changes included in this patch revolve around documentation
and renaming the environment variable used to determine the Namespace
that the CARM ConfigMap resides in.

Previously, the environment variable controlling the Namespace the
ack-role-account-map ConfigMap was in was called K8S_NAMESPACE. I
thought this name was overly broad and confusing, considering we have a
--watch-namespace CLI flag for determining if the ACK controller is
started in "Cluster Mode" or "Namespace Mode", and the generic
K8S_NAMESPACE environment variable name was being confused with this
entirely unrelated CLI flag. I have thus renamed K8S_NAMESPACE to
ACK_SYSTEM_NAMESPACE to more accurately reflect what the variable
configures. I have left support for falling back to the old, now
deprecated K8S_NAMESPACE name, however.

Finally, I removed the hard-coded string ack-system comparison in the
CARM Account cache and now have it checking the ConfigMap's Namespace
against the value of the ACK_SYSTEM_NAMESPACE environment variable.

Note that I have run RDS controller local kind tests against this
version of the ACK runtime to ensure there are no nasty surprises and
all e2e tests are passing properly.

Issue: aws-controllers-k8s/community#1173

Signed-off-by: Jay Pipes jaypipes@gmail.com

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license.

In order to allow the ClusterRole associated with the ServiceAccount of
a controller started in Cluster Mode to require Read/List/Watch
permissions on Secrets in ALL Kubernetes Namespaces, we need to change
the way that Secret values are read in the resource reconciler.

When a "normal" client-go Kubernetes client is created and a single
watch namespace is *not* provided, then whenever that client is used to
read object information, a new SharedInformer cache is created for that
Kind of resource across *all* Namespaces.

This SharedInformer cache sets up listers and watchers on all resources
of that Kind of resource across all Namespaces and thus the ClusterRole
associated with the ServiceAccount of the controller needs permissions
to get, list and watch those resources across all Namespaces.

For Secret resources, this permission to list/watch Secrets across all
Namespaces is too broad for many security-conscious organizations. For
these organizations, they wish to restrict the ACK controller to only
watch Secret resources that are in specific Namespaces that the ACK
custom resources are created in.

In order to fulfill this security requirement, we needed to make a
relatively small change to the resource reconciler's
SecretValueFromReference method to use the non-caching apiReader part of
the Kubernetes client.

The other changes included in this patch revolve around documentation
and renaming the environment variable used to determine the Namespace
that the CARM ConfigMap resides in.

Previously, the environment variable controlling the Namespace the
`ack-role-account-map` ConfigMap was in was called `K8S_NAMESPACE`. I
thought this name was overly broad and confusing, considering we have a
`--watch-namespace` CLI flag for determining if the ACK controller is
started in "Cluster Mode" or "Namespace Mode", and the generic
`K8S_NAMESPACE` environment variable name was being confused with this
entirely unrelated CLI flag. I have thus renamed `K8S_NAMESPACE` to
`ACK_SYSTEM_NAMESPACE` to more accurately reflect what the variable
configures. I have left support for falling back to the old, now
deprecated `K8S_NAMESPACE` name, however.

Finally, I removed the hard-coded string `ack-system` comparison in the
CARM Account cache and now have it checking the ConfigMap's Namespace
against the value of the `ACK_SYSTEM_NAMESPACE` environment variable.

Note that I have run RDS controller local kind tests against this
version of the ACK runtime to ensure there are no nasty surprises and
all e2e tests are passing properly.

Issue: aws-controllers-k8s/community#1173

Signed-off-by: Jay Pipes <jaypipes@gmail.com>
Copy link
Contributor

@vijtrip2 vijtrip2 left a comment

Choose a reason for hiding this comment

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

Looks good!

We should also update the community CARM docs to let customers know about these new environment variables, right?

object, ok := raw.(*corev1.Namespace)
return ok &&
(object.ObjectMeta.Name == "ack-system" ||
(object.ObjectMeta.Name == ackSystemNamespace ||
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch

// envVarDeprecatedK8sNamespace is the string key for the old, deprecated
// environment variable storing the Kubernetes Namespace we use for
// ConfigMaps and other ACK system configuration needs.
envVarDeprecatedK8sNamespace = "K8S_NAMESPACE"
Copy link
Member

@a-hilaly a-hilaly Feb 14, 2022

Choose a reason for hiding this comment

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

We should also change K8S_NAMESPACE to ACK_SYSTEM_NAMESPACE in helm/deployment.yaml and config/controller/deployment.yaml

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I've got a patch for that to code-generator. I'll submit it once we release the runtime (since I will pin code-generator to that runtime version)

@jaypipes
Copy link
Collaborator Author

Looks good!

We should also update the community CARM docs to let customers know about these new environment variables, right?

Yep. I did that here: aws-controllers-k8s/community#1178

@vijtrip2
Copy link
Contributor

/lgtm

@ack-bot ack-bot added the lgtm Indicates that a PR is ready to be merged. label Feb 14, 2022
@ack-bot
Copy link
Collaborator

ack-bot commented Feb 14, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: A-Hilaly, jaypipes, vijtrip2

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [A-Hilaly,jaypipes,vijtrip2]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ack-bot ack-bot merged commit 0701cb8 into aws-controllers-k8s:main Feb 14, 2022
jaypipes added a commit to jaypipes/ack-code-generator that referenced this pull request Feb 15, 2022
This is the patch that corresponds to changes made to ACK runtime to
rename the `K8S_NAMESPACE` environment variable to
`ACK_SYSTEM_NAMESPACE` to better represent what this variable referred
to.

Related: aws-controllers-k8s/runtime#72
Related: aws-controllers-k8s/community#1178
Issue: aws-controllers-k8s/community#1173

Signed-off-by: Jay Pipes <jaypipes@gmail.com>
jaypipes added a commit to jaypipes/ack-code-generator that referenced this pull request Feb 15, 2022
This is the patch that corresponds to changes made to ACK runtime to
rename the `K8S_NAMESPACE` environment variable to
`ACK_SYSTEM_NAMESPACE` to better represent what this variable referred
to.

Related: aws-controllers-k8s/runtime#72
Related: aws-controllers-k8s/community#1178
Issue: aws-controllers-k8s/community#1173

Signed-off-by: Jay Pipes <jaypipes@gmail.com>
jaypipes added a commit to jaypipes/ack-code-generator that referenced this pull request Feb 15, 2022
This is the patch that corresponds to changes made to ACK runtime to
rename the `K8S_NAMESPACE` environment variable to
`ACK_SYSTEM_NAMESPACE` to better represent what this variable referred
to.

Related: aws-controllers-k8s/runtime#72
Related: aws-controllers-k8s/community#1178
Issue: aws-controllers-k8s/community#1173

Signed-off-by: Jay Pipes <jaypipes@gmail.com>
ack-bot pushed a commit to aws-controllers-k8s/code-generator that referenced this pull request Feb 15, 2022
This is the patch that corresponds to changes made to ACK runtime to
rename the `K8S_NAMESPACE` environment variable to
`ACK_SYSTEM_NAMESPACE` to better represent what this variable referred
to.

Related: aws-controllers-k8s/runtime#72
Related: aws-controllers-k8s/community#1178
Issue: aws-controllers-k8s/community#1173

Signed-off-by: Jay Pipes <jaypipes@gmail.com>

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants