To deploy the s3sync-service in the labaws cluster while ensuring it connects to the same S3 bucket as the labci cluster—but with read-only access to prevent labaws from adding new data—you can follow these steps:
- Create Read-Only AWS Credentials
- Set Up a SealedSecret in the
labaws Cluster
- Deploy a
HelmRelease in the labaws Cluster
- Verify the Deployment
Below is a detailed guide for each step:
1. Create Read-Only AWS Credentials
Objective: Generate AWS credentials that allow read-only access to the specific S3 bucket.
Steps:
-
Access the AWS Management Console:
-
Create a New IAM Policy:
-
Go to Policies > Create Policy.
-
Choose the JSON tab and paste the following policy, replacing predprod-hollow-snapshots with your actual bucket name if different:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::predprod-hollow-snapshots",
"arn:aws:s3:::predprod-hollow-snapshots/*"
]
}
]
}
-
Click Review Policy, name it (e.g., S3ReadOnlyPolicy), and save it.
-
Create an IAM User with the Read-Only Policy:
- Go to Users > Add user.
- Enter a username (e.g.,
s3sync-readonly-user).
- Select Programmatic access for access type.
- Attach Existing Policies Directly and select the newly created
S3ReadOnlyPolicy.
- Complete the user creation process and download the Access Key ID and Secret Access Key. Store these securely as they won't be shown again.
2. Set Up a SealedSecret in the labaws Cluster
Objective: Store the read-only AWS credentials securely in the labaws Kubernetes cluster using Bitnami SealedSecrets.
Prerequisites:
- Kubectl Access: Ensure you have
kubectl configured to interact with the labaws cluster.
- SealedSecrets Controller: Ensure the SealedSecrets controller is installed in the
labaws cluster. If not, follow the Bitnami SealedSecrets installation guide.
Steps:
-
Create a Kubernetes Secret Manifest:
Create a file named s3sync-service-readonly-secret.yaml:
apiVersion: v1
kind: Secret
metadata:
name: s3sync-service-readonly
namespace: labaws
type: Opaque
data:
AWS_ACCESS_KEY_ID: <base64-encoded-access-key-id>
AWS_SECRET_ACCESS_KEY: <base64-encoded-secret-access-key>
-
Seal the Secret:
Use the kubeseal CLI to create a SealedSecret:
kubeseal --controller-namespace sealed-secrets --format yaml < s3sync-service-readonly-secret.yaml > s3sync-service-readonly-sealedsecret.yaml
- Note: Adjust the
--controller-namespace if your SealedSecrets controller is in a different namespace.
-
Apply the SealedSecret to the labaws Cluster:
kubectl apply -f s3sync-service-readonly-sealedsecret.yaml
- This creates a
SealedSecret in the labaws namespace, which the controller will decrypt into a regular Secret.
3. Deploy a HelmRelease in the labaws Cluster
Objective: Deploy the s3sync-service Helm chart in the labaws cluster using Flux's HelmRelease, referencing the read-only credentials.
Steps:
-
Create a HelmRelease Manifest:
Create a file named s3sync-service-helmrelease-labaws.yaml:
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
name: s3sync-service
namespace: labaws
spec:
chart:
spec:
chart: s3sync-service
version: 0.0.9
sourceRef:
kind: HelmRepository
name: artifactory
namespace: flux
interval: 15m
interval: 60m
releaseName: labaws-s3sync-service
values:
resources:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 100m
memory: 128Mi
secret:
name: s3sync-service-readonly
volumes:
- name: hollow-producer
persistentVolumeClaim:
claimName: hollow-producer
volumeMounts:
- name: hollow-producer
mountPath: /hollow-producer
readOnly: true
config:
aws_region: eu-west-1
upload_workers: 0 # Disable upload workers to prevent data from being pushed to S3
checksum_workers: 10
watch_interval: 30s
s3_ops_retries: 10
sites:
- name: labaws
local_path: /hollow-producer/publish-dir
bucket: predprod-hollow-snapshots
bucket_path: preprod/pre-nl/publish-dir
retire_deleted: true
Key Configurations:
- Secret Reference: The
secret.name points to the read-only SealedSecret you created.
- Disabling Uploads: Setting
upload_workers: 0 effectively disables any upload operations. Ensure the Helm chart respects this setting. If the chart has specific flags to disable uploads, use those as well.
- Volume and VolumeMounts: Ensure the PersistentVolumeClaim (
hollow-producer) exists in the labaws namespace or adjust accordingly.
-
Apply the HelmRelease:
kubectl apply -f s3sync-service-helmrelease-labaws.yaml
- This tells Flux to deploy the
s3sync-service with the specified configuration in the labaws cluster.
4. Verify the Deployment
Objective: Ensure that the s3sync-service is functioning correctly in the labaws cluster with read-only access.
Steps:
-
Check Pod Status:
kubectl get pods -n labaws -l app=s3sync-service
- Ensure all pods are running without errors.
-
Inspect Logs:
kubectl logs -n labaws deployment/labaws-s3sync-service
- Look for any errors related to S3 access. Successful logs should indicate synchronization from S3 to the local path without attempting uploads.
-
Test Read-Only Access:
- Attempt Upload from
labaws Cluster:
- Try to place a file in the
/hollow-producer/publish-dir directory and observe if s3sync-service attempts to upload it to S3. It should fail or not attempt if uploads are disabled.
- Verify S3 Bucket:
- Check the S3 bucket (
predprod-hollow-snapshots) to ensure no new data from the labaws cluster is present.
-
Monitor Flux and HelmRelease:
- Ensure that Flux has successfully reconciled the
HelmRelease and that there are no pending updates or errors.
flux get helmreleases -n labaws
- Look for the status of the
s3sync-service HelmRelease.
Additional Considerations
-
Separate IAM Users: Using different IAM users for labci (read-write) and labaws (read-only) enhances security by enforcing the principle of least privilege.
-
Network Policies: If applicable, ensure that network policies in the labaws cluster allow outbound access to S3.
-
Monitoring and Alerts: Set up monitoring to detect any unauthorized attempts to write to S3 from the labaws cluster.
-
Documentation and Version Control: Keep all manifests under version control and document the configuration for future reference and audits.
By following these steps, you'll successfully deploy the s3sync-service in the labaws cluster with read-only access to the shared S3 bucket, ensuring data consistency without allowing labaws to modify the bucket contents.