Repository navigation
Rd 1598 - #7
Rd 1598#7pegahnikbakht wants to merge 9 commits into
Conversation
There was a problem hiding this comment.
Looks good overall but it really gets a bit complicated to just enable cloud-init for RHEL on GCP.
Overall it is really annoying that RHEL decided to go this route for GCP. It seems like there are three possible solutions/approaches:
- Use only the startup-script from GCP, which would mean we have to maintain that script for GCP and cannot rely on the same cloud-init
- Bake a custom image with cloud init. I think we wouldn't do this and leave that to the customer.
- Bootstrap cloud-init in the startup-script, which is the approach of this PR
I like the approach of the PR, but it gets really quite messy fast with approach 3. I personally believe that in these cases it might be better to just require cloud-init to be enabled in the image and simply not support RHEL on GCP for that purpose. Customers can then do approach 2, with maybe some guidance, and then we kind of leave Tower out of it.
@xstecuc what is your opinion on this?
If we decide to go this route I have some comments below. Changes to the cloud-init will likely conflict or get lost with the introduction of tower-commons so we should go over what is necessary.
| - libtss2-dev | ||
| - jq | ||
|
|
||
| runcmd: |
There was a problem hiding this comment.
With tower-commons we can instead declare which packages to install from terraform. It might be worth syncing this with the tower commons changes (when it gets merged), to avoid this workaround.
| set -euo pipefail | ||
|
|
||
| cat /home/${USERNAME}/tokens >> /etc/environment | ||
| if [[ -f /home/${USERNAME}/tokens ]]; then |
There was a problem hiding this comment.
What does this do?
Does it translate between /home/${USERNAME}/tokens and /etc/canarybit/tokens?
There was a problem hiding this comment.
I got permission deny on rhel because of SELinux policy:
The RHEL error is caused by SELinux, not ordinary file permissions. The AVC record showed systemd (init_t) was denied access to tokens labeled user_home_t. The file being readable by root (0644) doesn’t override SELinux policy. Ubuntu usually doesn’t enforce SELinux with this policy, which explains why it behaves differently there.
| mv ${CB_INSPECTOR_CLIENT_V}/cb-inspector-client /usr/local/bin/cb-inspector-client | ||
|
|
||
| # Start cb-inspector-client as System service once and then a defined frequency | ||
| systemctl daemon-reload |
|
|
||
| # Download the CanaryBit Inspector agent (cb-inspector-client) into /usr/local/bin | ||
| cb download cb-inspector-client ${CB_INSPECTOR_CLIENT_V}/cb-inspector-client; chmod +x ${CB_INSPECTOR_CLIENT_V}/cb-inspector-client; mv ${CB_INSPECTOR_CLIENT_V}/cb-inspector-client /usr/local/bin/cb-inspector-client | ||
| curl -fsSL https://canarybit-public-binaries.s3.eu-west-1.amazonaws.com/cb-cli/${CBCLI_V}/cb-x86_64-unknown-linux-gnu -o /usr/local/bin/cb |
There was a problem hiding this comment.
I also prefer this, but I am curious why it got changed. It can still be one line if we want (just add the ;)
This will likely be replaced by tower-commons so if this format is needed for some cloud-init implementation make sure to document it
There was a problem hiding this comment.
Ah just saw the description to the PR, that makes sense, then we will likely prefer this over chmod +x in the future.
| } | ||
| } | ||
|
|
||
| resource "null_resource" "cloud_init_reboot" { |
There was a problem hiding this comment.
Can this be moved to a separate file, since it is quite a specific workaround?
There was a problem hiding this comment.
Agree that it get a bit messy in GCP.
| variable "os_name" { | ||
| description = "Operating system family used to configure OS-specific bootstrap steps" | ||
| type = string | ||
| default = "ubuntu" |
There was a problem hiding this comment.
Does the value "ubuntu" currently do anything?
In case it doesn't we could consider to have the variable be "rhel_workarounds_enabled" or something similar. Then it is fairly clear that it only relates to rhel. On the other hand this shows the end user directly what we have tested on.
There was a problem hiding this comment.
ubuntu does not do anything now, but there might be some other OS in future that we test and see they require some specific change, do you think we still can use "workarounds_enabled" for them?
| "echo 'Waiting for cloud-init installation'", | ||
| "for i in $(seq 1 120); do command -v cloud-init >/dev/null 2>&1 && break; sleep 5; done", | ||
| "command -v cloud-init >/dev/null 2>&1 || { echo 'Timed out waiting for cloud-init installation' >&2; exit 1; }", | ||
| "sudo systemd-run --no-block --unit=terraform-cloud-init-reboot --on-active=10s /usr/sbin/reboot", |
There was a problem hiding this comment.
Not sure if it works, but potentially we could skip the reboot if we don't use anything from cloud-init that runs early on.
Something like (got it from LLM):
# Run all stages in order (init-local, init, modules:config, modules:final)
cloud-init clean --logs
cloud-init init --local
cloud-init init
cloud-init modules --mode=config
cloud-init modules --mode=final
It might be quite messy though if someone wants to use something extra from cloud-init
|
@antoniacobaeus yes, I agree with you! I think we should just mention in our docs that "Tower does not support OS images that do not have cloud-init pre-installed!". |
antoniacobaeus
left a comment
There was a problem hiding this comment.
LGTM
We can add the same OS_NAME variable to tower-commons. Then it might make sense to only do the validation there, to kind of reduce the space, but we can leave that for later.
These same changes are probably needed later in tower premium as well
There are a couple of fixes in this PR for RHEL:
First fixing the package name.
Then fixing the permission deny issue because of SELinux policy on running cbclient, now the tokens will move to /etc/canarybit/tokens
The RHEL error is caused by SELinux, not ordinary file permissions. The AVC record showed systemd (init_t) was denied access to tokens labeled user_home_t. The file being readable by root (0644) doesn’t override SELinux policy. Ubuntu usually doesn’t enforce SELinux with this policy, which explains why it behaves differently there.
Then fix the cloud-init on GCP. Now there is a launcher script on GCP that first install cloud-init and do a reboot and then the cloud-init will run after that.