Skip to content

Commit

Permalink
Allow file downloads in STIG mode
Browse files Browse the repository at this point in the history
This commit fixes an issue that was preventing STIG mode file downloads as
well as a few opportuninistic fixes.

* Add LOGIN_ONETIME_PASSWORD to session types enum
* Allow token generation for user sessions
* Add comments to explain generate_tokens arguments in download method

(cherry picked from commit fab04ec)
  • Loading branch information
anodos325 authored and bugclerk committed Feb 17, 2025
1 parent 4628d65 commit da2bba0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/middlewared/middlewared/api/v25_04_0/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class AuthSessionEntry(BaseModel):
'UNIX_SOCKET',
'LOGIN_PASSWORD',
'LOGIN_TWOFACTOR',
'LOGIN_ONETIME_PASSWORD',
'API_KEY',
'TOKEN',
'TRUENAS_NODE',
Expand Down
1 change: 0 additions & 1 deletion src/middlewared/middlewared/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def __init__(self, user: dict, assurance: AuthenticatorAssuranceLevel | None):
self.last_used_at = now

if assurance:
self.may_create_auth_token = AuthMech.TOKEN_PLAIN in assurance.mechanisms
self.expiry = now + self.assurance.max_session_age
self.inactivity_timeout = self.assurance.max_inactivity

Expand Down
7 changes: 6 additions & 1 deletion src/middlewared/middlewared/service/core_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,12 @@ async def _download(self, app, method, args, filename, buffered):
pipes=Pipes(output=self.middleware.pipe(buffered))
)
token = await self.middleware.call(
'auth.generate_token', 300, {'filename': filename, 'job': job.id}, True, True, app=app
'auth.generate_token',
300, # ttl
{'filename': filename, 'job': job.id}, # attrs
True, # match origin
True, # single-use token
app=app
)
self.middleware.fileapp.register_job(job.id, buffered)
return job.id, f'/_download/{job.id}?auth_token={token}'
Expand Down

0 comments on commit da2bba0

Please sign in to comment.