Repository navigation
core: prompt securely when hashing passwords - #24126
Conversation
✅ Deploy Preview for authentik-integrations ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for authentik-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #24126 +/- ##
=======================================
Coverage 93.51% 93.52%
=======================================
Files 1062 1062
Lines 63854 63871 +17
Branches 424 424
=======================================
+ Hits 59716 59733 +17
Misses 4138 4138
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
|
@emilburzo Last release, we added a feature to put hashed passwords in docker composes, send to api, etc instead of sending plaintext. You generate the hashed password by running Do you feel that it is okay for the password to be plaintext in bash history optionally, or should this never be allowed? |
|
authentik PR Installation instructions Instructions for docker-composeAdd the following block to your AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-64d1cdaf501e3512b55b248bbff96bc1aad044bd
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)sAfterwards, run the upgrade commands from the latest release notes. Instructions for KubernetesAdd the following block to your authentik:
outposts:
container_image_base: ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s
global:
image:
repository: ghcr.io/goauthentik/dev-server
tag: gh-64d1cdaf501e3512b55b248bbff96bc1aad044bdAfterwards, run the upgrade commands from the latest release notes. |
|
(If we remove support, we would need to include this as a breaking change in the release notes due to how it might affect existing scripts and tooling. Just adding a reminder for myself) |
|
agree that it's not good practice, besides for human use, I think the interactive prompt is the way to go but I assume we likely want/should also support automation? then I think supporting an environment variable and/or standard input would work -- does that make sense? |
f39f575 to
e84518a
Compare
e84518a to
0c0b5e9
Compare
PeshekDotDev
left a comment
There was a problem hiding this comment.
The only other thing, I think we should document how to run the command with the sed filter I had mentioned. IE for when we need to prepend all $'s with a $ for docker compose files
dewi-tik
left a comment
There was a problem hiding this comment.
Agree with Connor's comment, otherwise LGTM
✅ Deploy Preview for authentik-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
f247aa2 to
0d008d1
Compare
| For automation, pass the password in the `PASSWORD` environment variable and pipe it through standard input to prevent exposing the password in your shell history. The `-T` option disables pseudo-TTY allocation so that the command reads from standard input: | ||
|
|
||
| ```bash | ||
| printf '%s\n' "$PASSWORD" | docker compose run --rm -T server hash_password |
There was a problem hiding this comment.
is the -T really needed? it seems to work without it
$ printf '%s\n' "$PASSWORD" | docker compose run --rm server hash_password
pbkdf2_sha256$1000000$IfRvgi6VkGkwXXXXXXXXXXXXXXta/T8f8tHriB9xacQcI8p0Gpko=| For automation, pass the password in the `PASSWORD` environment variable and pipe it through standard input to prevent exposing the password in your shell history. The `-T` option disables pseudo-TTY allocation so that the command reads from standard input: | ||
|
|
||
| ```bash | ||
| printf '%s\n' "$PASSWORD" | docker compose run --rm -T server hash_password |
There was a problem hiding this comment.
NIT: echo "$PASSWORD" instead of printf seems cleaner, since you need a newline anyway, or am I missing some detail?
There was a problem hiding this comment.
(Also possibly add an example like
[...] < passwordfile
)
0d008d1 to
b8133a3
Compare
| if password != password_again: | ||
| raise CommandError(_("Passwords do not match")) | ||
| else: | ||
| password = sys.stdin.readline().rstrip("\r\n") |
There was a problem hiding this comment.
Why is this not just
| password = sys.stdin.readline().rstrip("\r\n") | |
| password = input() |
?
|
|
||
| from django.contrib.auth.hashers import make_password | ||
| from django.core.management.base import BaseCommand, CommandError | ||
| from django.utils.translation import gettext as _ |
There was a problem hiding this comment.
What is the use for translations in a management command?
| (["test123", "different"], "Passwords do not match"), | ||
| (KeyboardInterrupt, "Aborted"), | ||
| ): | ||
| with self.subTest(message=message), self.assertRaises(CommandError) as ctx: |
There was a problem hiding this comment.
Generally authentik's codebase doesn't use subTest for cases this small. The (KeyboardInterrupt, "Aborted"), is overkill, the two others should just be unabstracted.
|
|
||
| def test_hash_password_empty_fails(self): | ||
| """Test that empty password raises error.""" | ||
| def test_hash_password_argument_fails(self): |
There was a problem hiding this comment.
This is good to test at the time of this PR, but it won't ever be needed in the future. Remove please.
|
|
||
| def test_hash_password(self): | ||
| """Test hashing a password.""" | ||
| def call_prompt(self, side_effect, **options): |
There was a problem hiding this comment.
This abstraction is most likely not needed. As far as I can tell, there should be exactly one test that uses this function: the one that tests whether the prompt works. Every other test should just stdin.
| For automation, pass the password in the `PASSWORD` environment variable and pipe it through standard input to prevent exposing the password in your shell history. The `-T` option disables pseudo-TTY allocation so that the command reads from standard input: | ||
|
|
||
| ```bash | ||
| printf '%s\n' "$PASSWORD" | docker compose run --rm -T server hash_password |
There was a problem hiding this comment.
(Also possibly add an example like
[...] < passwordfile
)
9728a2a to
fe323fc
Compare
fe323fc to
b273dc0
Compare
b273dc0 to
64d1cda
Compare
* main: (172 commits) web/admin: QOL: Add "Expiring in `n` days" and "Expiring today" notices to LicenseStatusCard (#24300) stages/authenticator: protect devices from stage deletion (#24324) core: prompt securely when hashing passwords (#24126) events: show account changes in user event history (#24323) website/integrations: The Lounge: cleanup (#23628) ci: bump taiki-e/install-action from 2.83.4 to 2.84.0 in /.github/actions/setup (#24312) ci: add working dir prefix to file paths (#24319) core, web: update translations (#24304) packages/ak-common/tracing: make console subscriber optional (#24219) website: bump the build group in /website with 6 updates (#24305) core: bump pnpm/pnpm from 11.15.0 to 11.15.1 in /lifecycle/container (#24308) core: bump pnpm/pnpm from 11.15.0 to 11.15.1 in /website (#24309) core: bump constructs from 10.6.0 to 10.7.0 (#24310) core: bump uuid from 1.23.5 to 1.24.0 (#24311) enterprise/providers/ws_fed: add SAML 1.1 support (#23851) web/admin: enterprise status card properties (#24170) web/elements: update the progress bar (#24134) web/maint: upgrade ak-divider (#24082) web/bug: harmonize and make routine the display of tasks (part 6: sch… (#23859) web/maint: upgrade ak-toggle-group (#24038) ...

Generating a password hash currently requires placing the plaintext password on the command line, where it can be retained in shell history and exposed through process inspection. The command now prompts twice without echoing when standard input is a terminal, or reads one password from standard input for automation.
Follow up to: #24118