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

Control locale during Ansible runs #4252

Merged
merged 3 commits into from
Mar 14, 2019
Merged

Conversation

rmol
Copy link
Contributor

@rmol rmol commented Mar 8, 2019

Status

Ready for review

Description of Changes

To avoid non-English system locales from breaking tasks that parse command output expecting English, set the environment variable LC_ALL=C in each play of securedrop-prod.yml.

Fixes #4219.

Testing

Install app and mon with a non-English locale. Verify that running securedrop-admin install completes without errors. If it breaks on tasks in install_tor.yml, or anywhere else, this fix has not worked.

Checklist

If you made changes to securedrop-admin:

  • Linting and tests (make -C admin test) pass in the admin development container

If you made non-trivial code changes:

  • I have written a test plan and validated it for this PR

@emkll
Copy link
Contributor

emkll commented Mar 12, 2019

I will be testing this will the following plan

  • Set up Prod VMs (14.04) with french locale (setting the contents of /etc/default/locale [0]) and running sudo locale-gen fr_FR && sudo locale-gen fr_FR.UTF-8 && sudo update-locale
  • Reboot and ensure locale returns [0], that various tooling is in French
  • Install on this branch from Tails, and ensure the testing completes successfully
  • Upgrade to 16.04 and re-run the playbook

[0] Contents of /etc/default/locale:

LANG=fr_FR.UTF-8
LANGUAGE="fr_FR.UTF-8"
LC_CTYPE="fr_FR.UTF-8"
LC_NUMERIC="fr_FR.UTF-8"
LC_TIME="fr_FR.UTF-8"
LC_COLLATE="fr_FR.UTF-8"
LC_MONETARY="fr_FR.UTF-8"
LC_MESSAGES="fr_FR.UTF-8"
LC_PAPER="fr_FR.UTF-8"
LC_NAME="fr_FR.UTF-8"
LC_ADDRESS="fr_FR.UTF-8"
LC_TELEPHONE="fr_FR.UTF-8"
LC_MEASUREMENT="fr_FR.UTF-8"
LC_IDENTIFICATION="fr_FR.UTF-8"
LC_ALL="fr_FR.UTF-8"

Copy link
Contributor

@emkll emkll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me so far (one comment inline). I have tested this branch using the above test plan:

  • Set up Prod VMs (14.04) with french locale (setting the contents of /etc/default/locale [0]) and running sudo locale-gen fr_FR && sudo locale-gen fr_FR.UTF-8 && sudo update-locale
  • Reboot and ensure locale returns [0], that various tooling is in French
  • Install on this branch from Tails, and ensure the testing completes successfully
  • Upgrade to 16.04 and re-run the playbook

I will test on hardware tomorrow morning, based on the instructions provided in #4219 (comment)

@@ -2,6 +2,8 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to also apply these changes to securedrop-staging.yml?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summarizing out of band discussion, we should also add the locale blocks to the other "prod" SD playbooks, such as -logs and -backup. Technically only -logs uses register, which is how we first encountered the error we're aiming to resolve here, but adding coverage to the other playbooks will also let us broaden the config test and reuse the existing "check all prod SD playbooks" logic.

I'll tack on a commit to implement this before final review.

@@ -2,6 +2,8 @@
---
- name: Ensure validation is run before prod install
hosts: localhost
environment:
LC_ALL: C
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about validating that this variable is set (via assert or otherwise) at the start of each play?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than an assert statement, we can add a config test (to be run in CI) that confirms the environment is set as expected on every play. See here for an example: https://github.com/freedomofpress/securedrop/blob/10a2eeedc3c22fd39e6a7eda4ca8f4bca1ca6024/molecule/ansible-config/tests/test_max_fail_percentage.py

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rmol has already added the corresponding config test here, which will help guard against regressions in the future: if new plays are added without the explicit locale declaration, CI will report an error.

rmol added 2 commits March 13, 2019 15:43
To avoid non-English system locales from breaking tasks that parse
command output expecting English, set the environment variable
LC_ALL=C in each play of securedrop-prod.yml.
Add configuration test to check locale is set for all plays there and
in securedrop-prod.
Porting the locale override logic by @rmol to the usual medley of
SecureDrop prod playbooks. Correspondingly updates the config tests to
reuse the "all prod playbooks" lookup logic, so we're sure to retain
coverage into the future.
@conorsch
Copy link
Contributor

Tacked on a commit porting the locale overrides to all production playbooks, with corresponding config test update.

Copy link
Contributor

@conorsch conorsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving based on visual review of changes, as well as @emkll's detailed test report.

@kushaldas
Copy link
Contributor

@emkll I tried sudo locale-gen fr_FR && sudo locale-gen fr_FR.UTF-8 && sudo update-locale many times, but, could not set the locale properly. What am I missing?

@rmol
Copy link
Contributor Author

rmol commented Mar 14, 2019

@kushaldas I think you need to pass to update-locale the environment variables you want active in /etc/default/locale, e.g. sudo update-locale LANG=fr_FR.UTF8. I'd add the --reset flag as well, which will comment out any variables present in the file that you don't pass.

Copy link
Contributor

@emkll emkll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on @rmol's instructions, a minimal way to change locale on VMs:

  1. sudo locale-gen fr_FR.UTF-8
  2. sudo update-locale --reset LANG=fr_FR.UTF-8
  3. sudo reboot

Once that was done, followed this test plan:

  • Installs successfully on this branch
  • Infra tests pass
  • ./securedrop-admin backup and ./securedrop-admin restore complete successfully
  • ./securedrop-admin logs completes successfully
  • ./securedrop-admin tailsconfig completes successfully

LGTM!

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.

Ansible scripts depend on English locale
4 participants