Skip to content

Conversation

benaryorg
Copy link

@benaryorg benaryorg commented Sep 29, 2025

Details

Effectively this fixes s3 signatures for custom domains.
The solution for this is somewhat hacky, however it does apply cleanly on version/2025.2.4 and I have tested it and can confirm that it works.
I'll set this to draft state because I do not currently have the capacity to finish the testing and linting, so if anyone wants to pick this up, please go ahead.
To be perfectly honest, I just copied the stuff I use to generate such links personally straight out of my shell history into the source code.
It is however the only solution that I have managed to find which actually works.
NB: this has only been tested when cherry-picked onto 2025.2.3 and 2025.8.3!
NB: this is more or less a bandaid, a proper rewrite of the method to generate the URl would be desirable IMHO, especially since it will compute the signature even when it is not needed. Using the proper class for the URl would also be good, to avoid any weirdnesses for edge-cases. Right now the onus of providing a working string is put on the admin.

The commit message is included verbatim below.


S3 signatures are fickle since there are several hashes of components which must ultimately be correct for the signature to match with no room for error.
Since both the host header as well as the path, the former by default, the latter necessarily.
The issue with custom domains is therefore that the host header mismatches unless the signature was created for that specific domain.
This is complicated further by boto3 making it incredibly difficult to actually sign a link with the path not containing the bucket prefix.
Therefore setting the endpoint alone does not work with a truly custom domain (i.e. one where the data resides on the root of the domain).

Changing this to a rather hacky workaround accessing fields of the internal data structures and grabbing the signer directly allows for signing the request.
This comes with several caveats such as the parameters going largely untouched, however in preliminary testing it works fine.
There are no superfluous slashes (i.e. no https://example.com//file.svg), no superfluous prefixes (i.e. https://example.com/example.com/example.com/file.svg), and there are no signature errors in general.
Uploads still work.
Reminder that the application cache may need clearing before the changes reflect in the non-admin UI.

Relates:


Checklist

  • Local tests pass (ak test authentik/)
  • The code has been formatted (make lint-fix)

If an API change has been made

  • The API schema has been updated (make gen-build)

If changes to the frontend have been made

  • The code has been formatted (make web)

If applicable

  • The documentation has been updated
  • The documentation has been formatted (make docs)

S3 signatures are fickle since there are several hashes of components which must ultimately be correct for the signature to match with no room for error.
Since both the *host* header as well as the path, the former by default, the latter necessarily.
The issue with custom domains is therefore that the *host* header mismatches unless the signature was created for that specific domain.
This is complicated further by *boto3* making it incredibly difficult to actually sign a link with the path *not* containing the bucket prefix.
Therefore setting the endpoint alone does not work with a truly custom domain (i.e. one where the data resides on the root of the domain).

Changing this to a rather hacky workaround accessing fields of the internal data structures and grabbing the signer directly allows for signing the request.
This comes with several caveats such as the parameters going largely untouched, however in preliminary testing it works fine.
There are no superfluous slashes (i.e. no `https://example.com//file.svg`), no superfluous prefixes (i.e. `https://example.com/example.com/example.com/file.svg`), and there are no signature errors in general.
Uploads still work.
Reminder that the application cache may need clearing before the changes reflect in the non-admin UI.

Relates:

- [issue 13463](https://redirect.github.com/goauthentik/authentik/issues/13463)
- [pr 14706 ](https://redirect.github.com/goauthentik/authentik/pull/14706)

Signed-off-by: benaryorg <[email protected]>
Copy link

netlify bot commented Sep 29, 2025

Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit 31b43d0
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/68da65f2f3eb7b0008f0501a
😎 Deploy Preview https://deploy-preview-17087--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.

Copy link

netlify bot commented Sep 29, 2025

Deploy Preview for authentik-docs failed. Why did it fail? →

Name Link
🔨 Latest commit 31b43d0
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/68da65f209c49700082d929b

Copy link

netlify bot commented Sep 29, 2025

Deploy Preview for authentik-integrations failed. Why did it fail? →

Name Link
🔨 Latest commit 31b43d0
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/68da65f21e6dda00085f76cc

@benaryorg
Copy link
Author

benaryorg commented Sep 29, 2025

sh: 1: cross-env: not found

and

npm error No workspaces found

I'm not 100% sure, but the CI failures sound unrelated to this PR.

@benaryorg
Copy link
Author

I have confirmed this patch to work on both 2025.2.3 and 2025.8.3 on my end.

Some of the files I uploaded intermediately (I think with a different patch) needed a reupload since their URLs had duplicate prefixes (https://id-static.benary.org/media/public/media/public/application-icons/50352242-5439-41e8-bc38-94a7a28535d2.svg).
Given that the files did not work at all prior to that I don't think this is much of a problem.

Removing the custom_domain option will yield the usual endpoint-based URls with valid signatures all the same.

Copy link

codecov bot commented Sep 29, 2025

Codecov Report

❌ Patch coverage is 16.66667% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.79%. Comparing base (ce1ea92) to head (31b43d0).
⚠️ Report is 2323 commits behind head on main.

Files with missing lines Patch % Lines
authentik/root/storages.py 16.66% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17087      +/-   ##
==========================================
+ Coverage   92.74%   92.79%   +0.05%     
==========================================
  Files         794      845      +51     
  Lines       40424    45853    +5429     
==========================================
+ Hits        37490    42550    +5060     
- Misses       2934     3303     +369     
Flag Coverage Δ
e2e 46.29% <0.00%> (-1.74%) ⬇️
integration 23.27% <0.00%> (-1.04%) ⬇️
unit 90.94% <16.66%> (+0.44%) ⬆️

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

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

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.

1 participant