Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nss-pam-webapi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
magicfelix
nss-pam-webapi
Commits
832d9e4a
Verified
Commit
832d9e4a
authored
3 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
[Cache] Add `persist` flag to tell `set_access_token` whether to write to $HOME or not
parent
45dfbc0c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/cache.rs
+23
-18
23 additions, 18 deletions
src/cache.rs
src/pam.rs
+3
-4
3 additions, 4 deletions
src/pam.rs
with
26 additions
and
22 deletions
src/cache.rs
+
23
−
18
View file @
832d9e4a
...
...
@@ -311,31 +311,36 @@ impl UserInfo {
///
/// This will store the token in memory in the `access_token` slot, and attempt to
/// write the token to disk afterwards
pub
fn
set_access_token
(
&
mut
self
,
token
:
BasicTokenResponse
)
->
Result
<
(),
io
::
Error
>
{
pub
fn
set_access_token
(
&
mut
self
,
token
:
BasicTokenResponse
,
persist
:
bool
)
->
Result
<
(),
io
::
Error
>
{
self
.access_token
=
Some
(
token
.clone
());
debug!
(
"Saved token in memory"
);
// Try to write user's token cache file
// We need to ensure privileges were dropped successfully to avoid symlink attacks
// cf. https://capec.mitre.org/data/definitions/132.html
let
res
=
match
self
.drop_privileges
()
{
Ok
(
_
)
=>
match
self
.place_user_cache_file
(
USER_TOKEN_FILENAME
.to_string
())
{
Ok
(
path
)
=>
{
debug!
(
"Storing token for in cache file"
);
save_json
(
path
,
token
)
if
persist
{
// Try to write user's token cache file
// We need to ensure privileges were dropped successfully to avoid symlink attacks
// cf. https://capec.mitre.org/data/definitions/132.html
let
res
=
match
self
.drop_privileges
()
{
Ok
(
_
)
=>
match
self
.place_user_cache_file
(
USER_TOKEN_FILENAME
.to_string
())
{
Ok
(
path
)
=>
{
debug!
(
"Storing token for in cache file"
);
save_json
(
path
,
token
)
},
Err
(
e
)
=>
{
error!
(
"Error getting cache path in user home: {}"
,
e
);
Err
(
e
)
}
},
Err
(
e
)
=>
{
error!
(
"Error
getting cache path
in user home: {}"
,
e
);
error!
(
"Error
dropping privileges to store token
in user home: {}"
,
e
);
Err
(
e
)
}
},
Err
(
e
)
=>
{
error!
(
"Error dropping privileges to store token in user home: {}"
,
e
);
Err
(
e
)
}
};
restore_privileges
();
return
res
;
};
restore_privileges
();
res
}
else
{
Ok
(())
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/pam.rs
+
3
−
4
View file @
832d9e4a
...
...
@@ -102,16 +102,15 @@ impl PamServiceModule for PamOidc {
// 1. ...mark getpwnam unsafe (prevent cache code from calling it)
set_is_getpwnam_safe
(
false
);
// 2. ...store the access token (will not go through to $HOME, as getpwnam
// is locked)
get_context_user
()
.set_access_token
(
t
.clone
())
.ok
();
// 2. ...store the access token in memory
get_context_user
()
.set_access_token
(
t
.clone
(),
false
)
.ok
();
// 3. ...call getpwnam ourselves without having the cache object locked
let
passwd
=
getpwnam_safe
(
username
.to_string
());
if
passwd
.is_ok
()
{
// 4. ...if getpwnam was successful, store the token again (this time,
// modulo other errors, it will go through to $HOME)
get_context_user
()
.set_passwd
(
passwd
.unwrap
());
get_context_user
()
.set_access_token
(
t
.clone
())
.ok
();
get_context_user
()
.set_access_token
(
t
.clone
()
,
true
)
.ok
();
}
// 5. ...unlock getpwnam again (somewhat unnecessary)
set_is_getpwnam_safe
(
true
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment