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

Add ansible CI workflow, move variables to vars* #40

Merged
merged 24 commits into from
Mar 20, 2024
Merged

Add ansible CI workflow, move variables to vars* #40

merged 24 commits into from
Mar 20, 2024

Conversation

pat-s
Copy link
Contributor

@pat-s pat-s commented Feb 2, 2024

  • Rename host for a clean name
  • Move variables out of playbook
  • Add apply workflow for main branch
  • Add check workflow for PRs

@anbraten
Copy link
Member

The pipelines to check the ansible configs looks really nice. Could you check it again, so we could merge it. Auto-deploying on main could be a bit too much for the beginning, maybe a manual pipeline would be better

@pat-s
Copy link
Contributor Author

pat-s commented Mar 14, 2024

@anbraten The workflow waits for a secret called ansible_vault_password. To connect to the instance, you also need to add an SSH key.

Overall, storing secrets as WP secrets is fine if they are imported as env vars, see e.g. https://codeberg.org/Codeberg-Infrastructure/configuration-as-code/src/commit/9b8cd385f277c403edf49ed14504957c9303fded/environments/production/group_vars/ci.yml#L5. This way, secrets are masked in WP log output automatically.

@anbraten
Copy link
Member

@pat-s Sorry. Just added the secret now.

@pat-s
Copy link
Contributor Author

pat-s commented Mar 19, 2024

vault-pass.secret does not exist in the repo. You probably don't want to add it.

If remote execution is the goal, using WP secrets would also be fine. Or an external secret manager which allows easier/safer CI integration.

@anbraten
Copy link
Member

anbraten commented Mar 19, 2024

In vault-pass.secret is just the secret which I've added to ansible_vault_password. Not sure what vault-password of the plugin expects. We could simply run echo "$${ansible_vault_password}" > vault-pass.secret before the plugin is executed if that helps.

@pat-s
Copy link
Contributor Author

pat-s commented Mar 19, 2024

It is likely due to drone-plugins/drone-ansible#31

See https://docs.ansible.com/ansible/latest/vault_guide/vault_managing_passwords.html#managing-multiple-passwords-with-vault-ids for using a file with ansible vault which holds all secrets.
To decrypt it, it seems one needs to use vault-id and vault-password-file. I am referring to group_vars/all/vault.yaml.

I haven't worked with ansible-vault before. Do you want to continue trying to get this working?

@anbraten
Copy link
Member

The ansible plugin restructuring introduced a bug. Fixed it in here: https://codeberg.org/woodpecker-plugins/ansible/pulls/10

@pat-s
Copy link
Contributor Author

pat-s commented Mar 20, 2024

Still the same error with the PR image.

@anbraten
Copy link
Member

That fixed it. Now we need to get the ssh key to work.

@anbraten
Copy link
Member

Works now. I changed the project to require approvals now, so no-one is stealing our credentials / changing sth.

@pat-s
Copy link
Contributor Author

pat-s commented Mar 20, 2024

Works now.

Great!

I changed the project to require approvals now, so no-one is stealing our credentials / changing sth.

Is this really needed? I thought long about this for Codebergs repo and came to the conclusion that stealing secrets is not really (easily) possible. Even when adding a custom shell command and cat'ing secrets, these are masked in the output if they are formatted as env vars. And the ansible diff doesn't expose them either. The only hacky way I could think about is sending a file to a remote storage and viewing the secrets there.

Maybe there is another (easy) way to forcefully expose secrets and work around that but I haven't found one yet. And even if, this would require triggering PRs against this repo first and nobody would attempt this / it can't be done hidden. Let me know if I overlook a possibility :)

@pat-s pat-s marked this pull request as ready for review March 20, 2024 14:28
@anbraten
Copy link
Member

anbraten commented Mar 20, 2024

Is this really needed? I thought long about this for Codebergs repo and came to the conclusion that stealing secrets is not really (easily) possible. Even when adding a custom shell command and cat'ing secrets, these are masked in the output if they are formatted as env vars. And the ansible diff doesn't expose them either. The only hacky way I could think about is sending a file to a remote storage and viewing the secrets there.

You can adjust the ansible config to do some action as root and you can adjust step in the woodpecker-ci config to not only check, but apply the config, so it would be basically free root access if I don't miss anything.

I think requiring approval for forks only would be really helpful, but my attempt to implement this for the most common "security modes" in woodpecker-ci/woodpecker#3348 wasn't liked too much 😕.

@pat-s
Copy link
Contributor Author

pat-s commented Mar 20, 2024

Oh dear! I was so focused on secrets all the time that I overlooked the most obvious exploit 🤦
Yes, one could just change check: false and become: true to apply commands as root 👀

Requiring approval for fork PRs adds a good protection layer yes as then only people with write access to the repo could open PRs which do not originate from forks.
That being said, I'll also protect the Codeberg pipelines now...thanks 🙄

@pat-s
Copy link
Contributor Author

pat-s commented Mar 20, 2024

Ready to merge?

@anbraten anbraten merged commit e8066f2 into main Mar 20, 2024
3 checks passed
@anbraten anbraten deleted the ansible branch March 20, 2024 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants