|
| 1 | +# Security hardening guide |
| 2 | + |
| 3 | +This document provides an overview of security features and guidance for hardening the security of [Charmed MySQL K8s](https://charmhub.io/mysql-k8s) deployments, including setting up and managing a secure environment. |
| 4 | + |
| 5 | +## Environment |
| 6 | + |
| 7 | +The environment where Charmed MySQL K8s operates can be divided into two components: |
| 8 | + |
| 9 | +1. Kubernetes |
| 10 | +2. Juju |
| 11 | + |
| 12 | +### Kubernetes |
| 13 | + |
| 14 | +Charmed MySQL K8s can be deployed on top of several Kubernetes distributions. The following table provides references for the security documentation for the main supported cloud platforms. |
| 15 | + |
| 16 | +| Cloud | Security guides | |
| 17 | +|--------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 18 | +| Charmed Kubernetes | [Security in Charmed Kubernetes](https://ubuntu.com/kubernetes/docs/security) | |
| 19 | +| 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) | |
| 20 | +| 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) | |
| 21 | +| GCP GKE | [Google security overview](https://cloud.google.com/kubernetes-engine/docs/concepts/security-overview), [Harden your cluster's security](https://cloud.google.com/kubernetes-engine/docs/concepts/security-overview) | |
| 22 | + |
| 23 | +### Juju |
| 24 | + |
| 25 | +Juju is the component responsible for orchestrating the entire lifecycle, from deployment to Day 2 operations. For more information on Juju security hardening, see the |
| 26 | +[Juju security page](/t/juju-security/15684) and the [How to harden your deployment](https://juju.is/docs/juju/harden-your-deployment) guide. |
| 27 | + |
| 28 | +#### Cloud credentials |
| 29 | + |
| 30 | +When configuring cloud credentials to be used with Juju, ensure that users have the correct permissions to operate at the required level on the Kubernetes cluster. Juju superusers responsible for bootstrapping and managing controllers require elevated permissions to manage several kinds of resources. For this reason, the K8s user for bootstrapping and managing the deployments should have full permissions, such as: |
| 31 | + |
| 32 | +* create, delete, patch, and list: |
| 33 | + * namespaces |
| 34 | + * services |
| 35 | + * deployments |
| 36 | + * stateful sets |
| 37 | + * pods |
| 38 | + * PVCs |
| 39 | + |
| 40 | +In general, it is common practice to run Juju using the admin role of K8s, to have full permissions on the Kubernetes cluster. |
| 41 | + |
| 42 | +#### Juju users |
| 43 | + |
| 44 | +It is very important that Juju users are set up with minimal permissions depending on the scope of their operations. Please refer to the [User access levels](https://juju.is/docs/juju/user-permissions) documentation for more information on the access levels and corresponding abilities. |
| 45 | + |
| 46 | +Juju user credentials must be stored securely and rotated regularly to limit the chances of unauthorized access due to credentials leakage. |
| 47 | + |
| 48 | +## Applications |
| 49 | + |
| 50 | +In the following sections, we provide guidance on how to harden your deployment using: |
| 51 | + |
| 52 | +1. Base images |
| 53 | +2. Charmed operator security upgrades |
| 54 | +3. Encryption |
| 55 | +4. Authentication |
| 56 | +5. Monitoring and auditing |
| 57 | + |
| 58 | +### Base images |
| 59 | + |
| 60 | +Charmed MySQL K8s and Charmed MySQL Router K8s run on top of the same rock (OCI-compliant rockcraft-based image). The rock is based on Ubuntu 22.04 and ships the MySQL distribution binaries built by Canonical. It is stored in a [GitHub registry](https://github.com/canonical/charmed-mysql-rock/pkgs/container/charmed-mysql) and is used as the base image for different pods providing MySQL services. |
| 61 | + |
| 62 | +### Charmed operator security upgrades |
| 63 | + |
| 64 | +[Charmed MySQL K8s operator](https://github.com/canonical/mysql-k8s-operator) and [Charmed MySQL Router K8s operator](https://github.com/canonical/mysql-router-k8s-operator) install pinned versions of the rock to provide reproducible and secure environments. New versions (revisions) of charmed operators can be released to update the operator's code, workloads, or both. It is important to refresh the charm regularly to make sure the workload is as secure as possible. |
| 65 | + |
| 66 | +For more information on upgrading Charmed MySQL K8s, see the [How to upgrade MySQL](https://canonical.com/data/docs/mysql/k8s/h-upgrade) and [How to upgrade MySQL Router](https://charmhub.io/mysql-router-k8s/docs/h-upgrade-intro) guides, as well as the [Release notes](https://canonical.com/data/docs/mysql/k8s/r-releases). |
| 67 | + |
| 68 | +### Encryption |
| 69 | + |
| 70 | +By default, encryption is optional for external connections. Internal communication between cluster members is always encrypted with TLS with self-signed certificates. |
| 71 | + |
| 72 | +To enforce encryption in transit for external connections, integrate Charmed MySQL K8s with a TLS certificate provider. 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 provider for your use case. |
| 73 | + |
| 74 | +Encryption in transit for backups is provided by the storage service (Charmed MySQL K8s is a client for an S3-compatible storage). |
| 75 | + |
| 76 | +For more information on encryption, see the [Cryptography](https://discourse.charmhub.io/t/charmed-mysql-k8s-explanations-cryptography/16783) explanation page and [How to enable encryption](https://canonical.com/data/docs/mysql/k8s/h-enable-tls) guide. |
| 77 | + |
| 78 | +### Authentication |
| 79 | + |
| 80 | +Charmed MySQL K8s uses the [caching_sha2_password](https://dev.mysql.com/doc/refman/8.0/en/caching-sha2-pluggable-authentication.html) plugin for authentication. |
| 81 | + |
| 82 | +### Monitoring and auditing |
| 83 | + |
| 84 | +Charmed MySQL K8s provides native integration with the [Canonical Observability Stack (COS)](https://charmhub.io/topics/canonical-observability-stack). To reduce the blast radius of infrastructure disruptions, the general recommendation is to deploy COS and the observed application into separate environments, isolated from one another. Refer to the [COS production deployments best practices](https://charmhub.io/topics/canonical-observability-stack/reference/best-practices) for more information or see the How to guides for MySQL K8s [monitoring](https://canonical.com/data/docs/mysql/k8s/h-enable-monitoring), [alert rules](https://canonical.com/data/docs/mysql/k8s/h-enable-alert-rules), and [tracing](https://canonical.com/data/docs/mysql/k8s/h-enable-tracing) for practical instructions. |
| 85 | + |
| 86 | +The Audit log plugin is enabled by default and produces login/logout logs. See the [Audit Logs](https://charmhub.io/mysql-k8s/docs/e-audit-logs) guide for further configuration. These logs are stored in the /var/log/mysql directory of the MySQL container and are rotated every minute to the /var/log/mysql/archive_audit directory. It’s recommended to integrate the charm with [COS](https://discourse.charmhub.io/t/9900), from where the logs can be easily persisted and queried using [Loki](https://charmhub.io/loki-k8s)/[Grafana](https://charmhub.io/grafana). |
| 87 | + |
| 88 | +## Additional Resources |
| 89 | + |
| 90 | +For details on the cryptography used by Charmed MySQL K8s, see the [Cryptography](https://discourse.charmhub.io/t/charmed-mysql-k8s-explanations-cryptography/16783) explanation page. |
0 commit comments