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
455ad071
"content/git@edugit.org:nbildhauer/teckids.org.git" did not exist on "34a0e62cf0fed109e606d5136584428cd40ae455"
Verified
Commit
455ad071
authored
3 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
[WIP][NSS] Implement token acquisition for NSS
parent
6450d545
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/nss.rs
+107
-1
107 additions, 1 deletion
src/nss.rs
with
107 additions
and
1 deletion
src/nss.rs
+
107
−
1
View file @
455ad071
...
@@ -13,13 +13,44 @@
...
@@ -13,13 +13,44 @@
* limitations under the License.
* limitations under the License.
*/
*/
use
crate
::
config
::
get_config
;
use
crate
::
config
::{
get_config
,
get_optional
};
use
config
::
Config
;
use
config
::
Config
;
use
crate
::
logging
::
setup_log
;
use
crate
::
logging
::
setup_log
;
use
serde
::
de
::
Deserialize
;
use
oauth2
::{
AuthUrl
,
ClientId
,
ClientSecret
,
RequestTokenError
,
Scope
,
TokenUrl
};
use
oauth2
::
basic
::
BasicClient
;
use
oauth2
::
reqwest
;
use
oauth2
::
reqwest
::
http_client
;
use
libnss
::
interop
::
Response
;
use
libnss
::
passwd
::{
PasswdHooks
,
Passwd
};
use
libnss
::
passwd
::{
PasswdHooks
,
Passwd
};
fn
get_or_nss_error
<
'de
,
T
:
Deserialize
<
'de
>>
(
config
:
&
Config
,
key
:
&
str
)
->
Result
<
T
,
Response
>
{
match
get_optional
(
config
,
key
)
{
Some
(
v
)
=>
{
debug!
(
"Configuration key found: {}"
,
key
);
return
Ok
(
v
);
},
None
=>
{
error!
(
"Configuration key not found: {}"
,
key
);
return
Err
(
Response
::
Unavail
);
},
}
}
fn
nss_hook_prepare
()
->
Config
{
fn
nss_hook_prepare
()
->
Config
{
let
conf
=
get_config
(
None
);
let
conf
=
get_config
(
None
);
...
@@ -32,10 +63,85 @@ fn nss_hook_prepare() -> Config {
...
@@ -32,10 +63,85 @@ fn nss_hook_prepare() -> Config {
return
conf
;
return
conf
;
}
}
fn
get_bearer_token
(
config
:
Config
)
->
Result
<
String
,
Response
>
{
let
client_id
=
ClientId
::
new
(
get_or_nss_error
(
&
config
,
"nss.client_id"
)
?
);
let
client_secret
=
match
get_optional
(
&
config
,
"nss.client_secret"
)
{
Some
(
v
)
=>
Some
(
ClientSecret
::
new
(
v
)),
None
=>
None
,
};
let
auth_url
=
match
AuthUrl
::
new
(
get_or_nss_error
(
&
config
,
"nss.auth_url"
)
?
)
{
Ok
(
u
)
=>
u
,
_
=>
{
error!
(
"Could not parse authorization URL"
);
return
Err
(
Response
::
Unavail
);
},
};
let
token_url
=
match
get_optional
(
&
config
,
"nss.token_url"
)
{
Some
(
v
)
=>
match
TokenUrl
::
new
(
v
)
{
Ok
(
u
)
=>
Some
(
u
),
Err
(
_
)
=>
{
error!
(
"Could not parse token URL"
);
return
Err
(
Response
::
Unavail
);
}
},
None
=>
None
,
};
let
scopes
:
Vec
<&
str
>
=
get_or_nss_error
(
&
config
,
"nss.scopes"
)
?
;
let
client
=
BasicClient
::
new
(
client_id
,
client_secret
,
auth_url
,
token_url
);
let
mut
request
=
client
.exchange_client_credentials
();
for
scope
in
scopes
{
request
=
request
.add_scope
(
Scope
::
new
(
scope
.to_string
()));
}
let
result
=
request
.request
(
http_client
);
match
result
{
Ok
(
t
)
=>
Ok
(
t
),
Err
(
e
)
=>
match
e
{
RequestTokenError
::
Request
(
re
)
=>
match
re
{
reqwest
::
Error
::
Reqwest
(
ree
)
=>
{
error!
(
"Request error requesting token: {}"
,
ree
);
return
Err
(
Response
::
Unavail
);
},
reqwest
::
Error
::
Http
(
he
)
=>
{
error!
(
"HTTP error requesting token: {}"
,
he
);
return
Err
(
Response
::
Unavail
);
},
reqwest
::
Error
::
Io
(
ioe
)
=>
{
error!
(
"IO error requesting token: {}"
,
ioe
);
return
Err
(
Response
::
Unavail
);
},
_
=>
{
error!
(
"Unknown error: {}"
,
re
);
return
Err
(
Response
::
Unavail
);
},
},
RequestTokenError
::
ServerResponse
(
t
)
=>
{
error!
(
"Authorization server returned error: {}"
,
t
);
return
Err
(
Response
::
Unavail
);
},
RequestTokenError
::
Parse
(
pe
,
_
)
=>
{
error!
(
"Error parsing response: {}"
,
pe
);
return
Err
(
Response
::
Unavail
);
},
_
=>
{
error!
(
"Unknown error: {}"
,
e
);
return
Err
(
Response
::
Unavail
);
},
},
}
}
fn
do_json_request
(
config
:
Config
,
url
:
String
)
->
Result
<
String
,
Response
>
{
let
token
=
get_bearer_token
(
config
)
?
;
}
struct
OidcPasswd
;
struct
OidcPasswd
;
impl
PasswdHooks
for
OidcPasswd
{
impl
PasswdHooks
for
OidcPasswd
{
fn
get_all_entries
()
->
Vec
<
Passwd
>
{
fn
get_all_entries
()
->
Vec
<
Passwd
>
{
let
config
=
nss_hook_prepare
();
vec!
[
vec!
[
Passwd
{
Passwd
{
name
:
"test"
.to_string
(),
name
:
"test"
.to_string
(),
...
...
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