Skip to content
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

feat: irsa checks #98

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

feat: irsa checks #98

wants to merge 5 commits into from

Conversation

leiicamundi
Copy link
Contributor

@leiicamundi leiicamundi commented Oct 30, 2024

This pull request introduces a substantial script designed to verify IRSA (IAM Roles for Service Accounts) configuration for deployments on Kubernetes.

While the script provides essential functionality, it's important to note that the error handling system is currently somewhat primitive could be nice tp plan to reevaluate it later to improve maintainability (SCRIPT_STATUS_OUTPUT).

https://github.com/camunda/team-infrastructure-experience/issues/25 associated with this pull request will reference the usage of the script in the documentation. The doc will also include a detailed explanation of using IRSA, the required format for IAM roles, and instructions on how to associate the necessary permissions.

Regarding testing, we plan to integrate c8-sm-checks into our reference architectures https://github.com/camunda/team-infrastructure-experience/issues/378. I have personally tested the script on a reference clusters of eks.

@leiicamundi leiicamundi added the enhancement New feature or request label Oct 30, 2024
@leiicamundi leiicamundi self-assigned this Oct 30, 2024
@leiicamundi leiicamundi marked this pull request as ready for review October 30, 2024 18:39
@@ -55,6 +58,43 @@ Options:

- `kubectl`: Required for interacting with Kubernetes clusters.

### IRSA Configuration Check (`/checks/kube/aws-irsa.sh`)
Copy link
Member

Choose a reason for hiding this comment

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

I'd add somewhere that a Helm chart release install is a requirement for this script.
E.g. helm template + kustomize or ArgoCD (uses helm template) would not result in Helm chart releases.

Usage: ./checks/kube/aws-irsa.sh [-h] [-n NAMESPACE] [-e EXCLUDE_COMPONENTS] [-p COMPONENTS_PG] [-l COMPONENTS_OS] [-s]
Options:
-h Display this help message
-n NAMESPACE Specify the namespace to use
Copy link
Member

Choose a reason for hiding this comment

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

since that's the only value that is required, should this be marked?

-e EXCLUDE_COMPONENTS Comma-separated list of components to exclude from the check (reference of the component is the root key used in the chart)
-p COMPONENTS_PG Comma-separated list of components to check IRSA for PostgreSQL (overrides default list)
-l COMPONENTS_OS Comma-separated list of components to check IRSA for OpenSearch (overrides default list)
-s Disable pod spawn for IRSA and network flow verification
Copy link
Member

Choose a reason for hiding this comment

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

maybe we could explain in a bit more detail what this means?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, it was supposed to be part of the documentation, but will not hurt to add some context here aswell


##### Example:
```bash
./checks/kube/aws-irsa.sh -n camunda-primary -p "identity,webModeler" -l "zeebe,operate"
Copy link
Member

Choose a reason for hiding this comment

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

curious how precise does the naming have to be?
Woudln't it be easier to just convert everything to lowercase, so customers can supply it however they want and we also don't have to care too much about special cases à la webModeler.

Maybe easier for the helm chart handling, just curious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

very precise (case sensitive) as we use the name of the component for jq queries.

Introducing key insensitivity in jq directly could be challenging (https://stackoverflow.com/questions/67725386/jq-unsensitive-case-key-filter), that said, we could have a static map at the beggining that does that for us.

I'll implement it

Copy link
Member

Choose a reason for hiding this comment

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

was just an idea, I'm also fine with keeping it as is.

Comment on lines +761 to +763
if [[ -z "$identity_keycloak_port" ]]; then
echo "[FAIL] identityKeycloak.externalDatabase.port is not defined in your helm values." 1>&2
SCRIPT_STATUS_OUTPUT=86
Copy link
Member

Choose a reason for hiding this comment

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

afaik I don't have to explicitly set it since the port by default is 5432

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, I've not tested the setup without explicit port so I can't tell you if the deployment works or not.
Also the chart does not have a default port set, so it will certainly fail.

I'll try to deploy without the port, if it works, then I'll fix this part not to throw an error and rather assume that's 5432 set as default port.

Comment on lines +1058 to +1062
if [[ -z "$role_arn" ]]; then
echo "[FAIL] The service account $service_account_name does not have a valid eks.amazonaws.com/role-arn annotation. You must add it in the chart, see https://docs.camunda.io/docs/self-managed/setup/deploy/amazon/amazon-eks/eks-helm/" 1>&2
SCRIPT_STATUS_OUTPUT=110
else
echo "[OK] The service account $service_account_name is bound to the role $role_arn by the eks.amazonaws.com/role-arn annotation."
Copy link
Member

@Langleu Langleu Oct 31, 2024

Choose a reason for hiding this comment

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

I didn't deploy it with IRSA, just wanted to see what happens.

[OK] The service account camunda-identity is bound to the role null by the eks.amazonaws.com/role-arn annotation
[INFO] Verifying role ARN (component=identity,serviceAccount=camunda-identity): null
[INFO] Running command: aws iam get-role --role-name "null"

obviously fails after that, but afaik should have already done so before.


[INFO] Running command: kubectl get serviceaccount "camunda-identity" -n "camunda" -o json
[INFO] Command output: {
    "apiVersion": "v1",
    "automountServiceAccountToken": true,
    "kind": "ServiceAccount",
    "metadata": {
        "annotations": {
            "meta.helm.sh/release-name": "camunda",
            "meta.helm.sh/release-namespace": "camunda"
        },
        "creationTimestamp": "2024-10-31T11:52:14Z",
        "labels": {
            "app": "camunda-platform",
            "app.kubernetes.io/component": "identity",
            "app.kubernetes.io/instance": "camunda",
            "app.kubernetes.io/managed-by": "Helm",
            "app.kubernetes.io/name": "camunda-platform",
            "app.kubernetes.io/part-of": "camunda-platform",
            "app.kubernetes.io/version": "8.6.2",
            "helm.sh/chart": "camunda-platform-11.0.2"
        },
        "name": "camunda-identity",
        "namespace": "camunda",
        "resourceVersion": "24758",
        "uid": "49c75019-c3cc-4088-ac68-2037e55770d1"
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need to do a double check of the returned values, good point

Copy link
Member

@Langleu Langleu left a comment

Choose a reason for hiding this comment

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

left some smaller comments to look into, nothing critical that has to be fixed in particular, except maybe the null and mentioning that's helm chart required.

I tried it out once without any IRSA and once with IRSA on just Postgres.

Overall worked quite well, I was just a bit overwhelmed by the output but I think if someone really uses it to debug, they would appreciate the verbosity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants