|
| 1 | +# Security hardening guide |
| 2 | + |
| 3 | +This document provides guidance and instructions to achieve |
| 4 | +a secure deployment of [Charmed Kafka K8s](https://github.com/canonical/kafka-k8s-bundle), including setting up and managing a secure environment. |
| 5 | +The document is divided into the following sections: |
| 6 | + |
| 7 | +1. Environment, outlining the recommendation for deploying a secure environment |
| 8 | +2. Applications, outlining the product features that enable a secure deployment of a Kafka cluster |
| 9 | +3. Additional resources, providing any further information about security and compliance |
| 10 | + |
| 11 | +## Environment |
| 12 | + |
| 13 | +The environment where applications operate can be divided in two components: |
| 14 | + |
| 15 | +1. Kubernetes |
| 16 | +2. Juju |
| 17 | + |
| 18 | +### Kubernetes |
| 19 | + |
| 20 | +Charmed Spark can be deployed on top of several Kubernetes distributions. |
| 21 | +The following table provides references for the security documentation for the |
| 22 | +main supported cloud platforms. |
| 23 | + |
| 24 | +| Cloud | Security guide | |
| 25 | +|--------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 26 | +| Charmed Kubernetes | [Security in Charmed Kubernetes](https://ubuntu.com/kubernetes/docs/security) | |
| 27 | +| AWS EKS | [Best Practices for Security, Identity and Compliance](https://aws.amazon.com/architecture/security-identity-compliance), [AWS security credentials](https://docs.aws.amazon.com/IAM/latest/UserGuide/security-creds.html#access-keys-and-secret-access-keys), [Security in EKS](https://docs.aws.amazon.com/eks/latest/userguide/security.html) | |
| 28 | +| Azure | [Azure security best practices and patterns](https://learn.microsoft.com/en-us/azure/security/fundamentals/best-practices-and-patterns), [Managed identities for Azure resource](https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/), [Security in AKS](https://learn.microsoft.com/en-us/azure/aks/concepts-security) | |
| 29 | + |
| 30 | +### Juju |
| 31 | + |
| 32 | +Juju is the component responsible for orchestrating the entire lifecycle, from deployment to Day 2 operations, of |
| 33 | +all applications. Therefore, Juju must be set up securely. For more information, see the |
| 34 | +[Juju security page](/t/juju-security/15684) and the [How to harden your deployment guide](https://juju.is/docs/juju/harden-your-deployment). |
| 35 | + |
| 36 | +#### Cloud credentials |
| 37 | + |
| 38 | +When configuring the cloud credentials to be used with Juju, ensure that the users have correct permissions to operate at the required level on the Kubernetes cluster. |
| 39 | +Juju superusers responsible for bootstrapping and managing controllers require elevated permissions to manage several kind of resources. For this reason, the |
| 40 | +K8s user used for bootstrapping and managing the deployments should have full permissions, such as: |
| 41 | + |
| 42 | +* create, delete, patch, and list: |
| 43 | + * namespaces |
| 44 | + * services |
| 45 | + * deployments |
| 46 | + * stateful sets |
| 47 | + * pods |
| 48 | + * PVCs |
| 49 | + |
| 50 | +In general, it is common practice to run Juju using the admin role of K8s, to have full permissions on the Kubernetes cluster. |
| 51 | + |
| 52 | +#### Juju users |
| 53 | + |
| 54 | +It is very important that juju users are set up with minimal permissions depending on the scope of their operations. |
| 55 | +Please refer to the [User access levels](https://juju.is/docs/juju/user-permissions) documentation for more information on the access level and corresponding abilities |
| 56 | +that the different users can be granted. |
| 57 | + |
| 58 | +Juju user credentials must be stored securely and rotated regularly to limit the chances of unauthorized access due to credentials leakage. |
| 59 | + |
| 60 | +## Applications |
| 61 | + |
| 62 | +In the following we provide guidance on how to harden your deployment using: |
| 63 | + |
| 64 | +1. Base images |
| 65 | +2. Charmed operator security upgrades |
| 66 | +3. Encryption |
| 67 | +4. Authentication |
| 68 | +5. Monitoring and auditing |
| 69 | + |
| 70 | +### Base images |
| 71 | + |
| 72 | +Charmed Kafka K8s and Charmed ZooKeeper K8s run on top of rockcraft-based image shipping the Apache Kafka and Apache ZooKeeper |
| 73 | +distribution binaries built by Canonical, and available in the [Kafka release page](https://launchpad.net/kafka-releases) and |
| 74 | +[ZooKeeper release page](https://launchpad.net/zookeeper-releases), respectively. Both images are based on Ubuntu 22.04. |
| 75 | +The images that can be found in the [Charmed Kafka rock](https://github.com/canonical/charmed-spark-rock) and |
| 76 | +[Charmed ZooKeeper rock](https://github.com/canonical/charmed-zookeeper-rock) Github repositories are used as the base |
| 77 | +images for the different pods providing Kafka and ZooKeeper services. |
| 78 | +The following table summarise the relation between the component and its underlying base image. |
| 79 | + |
| 80 | +| Component | Image | |
| 81 | +|-------------------|-------------------------------------------------------------------------------------------------------| |
| 82 | +| Charmed Kafka | [`charmed-kafka`](https://github.com/orgs/canonical/packages/container/package/charmed-kafka) | |
| 83 | +| Charmed ZooKeeper | [`charmed-zookeeper`](https://github.com/orgs/canonical/packages/container/package/charmed-zookeeper) | |
| 84 | + |
| 85 | +New versions of Charmed Kafka and Charmed ZooKeeper images may be released to provide patching of vulnerabilities (CVEs). |
| 86 | + |
| 87 | +### Charmed operator security upgrades |
| 88 | + |
| 89 | +Charmed Kafka K8s and Charmed ZooKeeper K8s operators install a pinned revision of the images outlined in the previous table |
| 90 | +in order to provide reproducible and secure environments. |
| 91 | +New versions of Charmed Kafka K8s and Charmed ZooKeeper K8s operators may therefore be released to provide patching of vulnerabilities (CVEs). |
| 92 | +It is important to refresh the charm regularly to make sure the workload is as secure as possible. |
| 93 | +For more information on how to refresh the charm, see the [how-to refresh](/t/charmed-kafka-k8s-documentation-how-to-upgrade/13267) user guide. |
| 94 | + |
| 95 | +### Wire Encryption |
| 96 | + |
| 97 | +In order to deploy a hardened solution, Charmed Kafka K8s must be deployed with wire encryption enabled. |
| 98 | +To do that, you need to relate Kafka and ZooKeeper charms to one of the TLS certificate operator charms. |
| 99 | +Please refer to the [Charming Security page](https://charmhub.io/topics/security-with-x-509-certificates) for more information on how to select the right certificate |
| 100 | +provider for your use-case. |
| 101 | + |
| 102 | +For more information on encryption setup, see the [How to enable encryption](/t/charmed-kafka-k8s-how-to-enable-encryption/10289) guide. |
| 103 | + |
| 104 | +### Authentication |
| 105 | + |
| 106 | +Charmed Kafka supports the following authentication layers: |
| 107 | + |
| 108 | +1. [SCRAM-based SASL Authentication](/t/charmed-kafka-k8s-how-to-manage-app/10293) |
| 109 | +2. [certificate-base Authentication (mTLS)](/t/create-mtls-client-credentials/11079) |
| 110 | +3. OAuth Authentication using [Hydra](/t/how-to-connect-to-kafka-using-hydra-as-oidc-provider/14610) or [Google](/t/how-to-connect-to-kafka-using-google-as-oidc-provider/14611) |
| 111 | + |
| 112 | +Each combination of authentication scheme and encryption is associated to the dedicated listener and it maps to a well-defined port. |
| 113 | +Please refer to the [listener reference documentation](/t/charmed-kafka-k8s-documentation-reference-listeners/13270) for more information. |
| 114 | + |
| 115 | +### Monitoring and auditing |
| 116 | + |
| 117 | +Charmed Kafka provides native integration with the [Canonical Observability Stack (COS)](https://charmhub.io/topics/canonical-observability-stack). |
| 118 | +To reduce the blast radius of infrastructure disruptions, the general recommendation is to deploy COS and the observed application into |
| 119 | +separate environments, isolated one another. Refer to the [COS production deployments best practices](https://charmhub.io/topics/canonical-observability-stack/reference/best-practices) |
| 120 | +for more information. |
| 121 | + |
| 122 | +Refer to How-To user guide for more information on: |
| 123 | +* [how to integrate the Charmed Kafka deployment with COS](/t/charmed-kafka-k8s-how-to-enable-monitoring/10291) |
| 124 | +* [how to customise the alerting rules and dashboards](/t/charmed-kafka-k8s-documentation-how-to-integrate-custom-alerting-rules-and-dashboards/13528) |
| 125 | + |
| 126 | +External user access to Kafka is logged to the `kafka-authorizer.log` that is pushes to [Loki endpoint](https://charmhub.io/loki-k8s) and exposed via [Grafana](https://charmhub.io/grafana), both components being part of the COS stack. |
| 127 | +Access denials are logged at INFO level, whereas allowed accesses are logged at DEBUG level. Depending on the auditing needs, |
| 128 | +customize the logging level either for all logs via the [`log_level`](https://charmhub.io/kafka-k8s/configurations?channel=3/stable#log_level) config option or |
| 129 | +only tune the logging level of the `authorizerAppender` in the `log4j.properties` file. Refer to the Reference documentation, for more information about |
| 130 | +the [file system paths](/t/charmed-kafka-k8s-documentation-reference-file-system-paths/13269). |
| 131 | + |
| 132 | +## Additional Resources |
| 133 | + |
| 134 | +For more information and details on the security and cryptography used by Charmed Kafka, see the [Security Explanation page](/t/charmed-kafka-k8s-documentation-explanation-security/15715). |
0 commit comments