Skip to content

core: prompt securely when hashing passwords - #24126

Merged
dominic-r merged 7 commits into
mainfrom
dominic/hash-password-prompt
Jul 23, 2026
Merged

dominic-r merged 7 commits into
mainfrom
dominic/hash-password-prompt

Conversation

@dominic-r

@dominic-r dominic-r commented Jul 16, 2026 •

Copy link
Copy Markdown
Member

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

@netlify

netlify Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-integrations ready!

Name Link
🔨 Latest commit 64d1cda
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/6a617b1dd94c5b00085fee23
😎 Deploy Preview https://deploy-preview-24126--authentik-integrations.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit 64d1cda
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6a617b1d128284000972cedc
😎 Deploy Preview https://deploy-preview-24126--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.52%. Comparing base (539da39) to head (64d1cda).
✅ All tests successful. No failed tests found.

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           
Flag Coverage Δ
conformance 35.49% <0.00%> (-0.01%) ⬇️
e2e 40.45% <0.00%> (-0.01%) ⬇️
integration 32.00% <0.00%> (-0.01%) ⬇️
rust 0.00% <ø> (ø)
unit 92.70% <100.00%> (+<0.01%) ⬆️
unit-migrate 92.73% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@PeshekDotDev

Copy link
Copy Markdown
Contributor

@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 docker compose run --rm server hash_password 'your-password'. This exposes the plaintext password in the bash history. My feeling is that we should never allow a user to run the command like this, and instead the command should be ran as docker compose run --rm server hash_password, and then the password is collected after, to keep bash history clean

Do you feel that it is okay for the password to be plaintext in bash history optionally, or should this never be allowed?

@github-actions

github-actions Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

authentik PR Installation instructions

Instructions for docker-compose

Add the following block to your .env file:

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)s

Afterwards, run the upgrade commands from the latest release notes.

Instructions for Kubernetes

Add the following block to your values.yml file:

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-64d1cdaf501e3512b55b248bbff96bc1aad044bd

Afterwards, run the upgrade commands from the latest release notes.

@dominic-r

Copy link
Copy Markdown
Member Author

(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)

@emilburzo

Copy link
Copy Markdown
Member

@PeshekDotDev

agree that it's not good practice, besides bash_history, it can also appear in the running process list (albeit shortly) or logged in places like CI/CD pipelines

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?

@PeshekDotDev PeshekDotDev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 dewi-tik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agree with Connor's comment, otherwise LGTM

@netlify

netlify Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit 64d1cda
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/6a617b1fb490800008c75b14
😎 Deploy Preview https://deploy-preview-24126--authentik-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@dominic-r
dominic-r requested a review from gergosimonyi July 21, 2026 14:12
@dominic-r
dominic-r force-pushed the dominic/hash-password-prompt branch from f247aa2 to 0d008d1 Compare July 21, 2026 14:30
Comment on lines +58 to +61
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

@emilburzo emilburzo Jul 21, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

NIT: echo "$PASSWORD" instead of printf seems cleaner, since you need a newline anyway, or am I missing some detail?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(Also possibly add an example like

[...] < passwordfile

)

@dominic-r
dominic-r force-pushed the dominic/hash-password-prompt branch from 0d008d1 to b8133a3 Compare July 21, 2026 16:05
if password != password_again:
raise CommandError(_("Passwords do not match"))
else:
password = sys.stdin.readline().rstrip("\r\n")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this not just

Suggested change
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 _

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(Also possibly add an example like

[...] < passwordfile

)

@dominic-r
dominic-r force-pushed the dominic/hash-password-prompt branch 3 times, most recently from 9728a2a to fe323fc Compare July 21, 2026 16:46
Copilot AI review requested due to automatic review settings July 22, 2026 01:42
@dominic-r
dominic-r force-pushed the dominic/hash-password-prompt branch from fe323fc to b273dc0 Compare July 22, 2026 01:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@dominic-r

Copy link
Copy Markdown
Member Author

:)

image

@github-project-automation github-project-automation Bot moved this from Todo to In Progress in authentik Core Jul 22, 2026
Copilot AI review requested due to automatic review settings July 23, 2026 02:23
@dominic-r
dominic-r force-pushed the dominic/hash-password-prompt branch from b273dc0 to 64d1cda Compare July 23, 2026 02:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@rissson
rissson requested a review from gergosimonyi July 23, 2026 16:02
@dominic-r
dominic-r merged commit 9478a91 into main Jul 23, 2026
123 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in authentik Core Jul 23, 2026
@dominic-r
dominic-r deleted the dominic/hash-password-prompt branch July 23, 2026 16:03
kensternberg-authentik added a commit that referenced this pull request Jul 23, 2026
* 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)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

7 participants