Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config for local JWT tokens #2568

Merged
merged 38 commits into from
Sep 7, 2023
Merged

Conversation

stveit
Copy link
Contributor

@stveit stveit commented Feb 6, 2023

Add config for info necessary for jwt tokens issued by the nav instance itself.
public key for configuring the oidc module, private key for signing and name for setting
'iss' and 'aud' claims.
Makes these values available through the JWTConf class.

Wraps errors are ConfigurationError, so other code that will later access the private key etc. only have to deal with that and not stuff like configparser.NoSectionError.

@stveit stveit self-assigned this Feb 6, 2023
@codecov
Copy link

codecov bot commented Feb 6, 2023

Codecov Report

Merging #2568 (8c8e00f) into master (b7f24ec) will increase coverage by 0.60%.
Report is 95 commits behind head on master.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2568      +/-   ##
==========================================
+ Coverage   54.20%   54.80%   +0.60%     
==========================================
  Files         558      560       +2     
  Lines       40634    40786     +152     
==========================================
+ Hits        22026    22354     +328     
+ Misses      18608    18432     -176     
Files Changed Coverage Δ
python/nav/jwtconf.py 100.00% <100.00%> (+5.40%) ⬆️

... and 26 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@github-actions
Copy link

github-actions bot commented Feb 6, 2023

Test results

     12 files       12 suites   13m 44s ⏱️
3 185 tests 3 185 ✔️ 0 💤 0
9 030 runs  9 030 ✔️ 0 💤 0

Results for commit 8c8e00f.

♻️ This comment has been updated with latest results.

@hmpf hmpf self-requested a review February 9, 2023 10:31
Copy link
Contributor

@hmpf hmpf left a comment

Choose a reason for hiding this comment

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

Codecov is complaining about missing tests and so am I.

python/nav/jwtconf.py Show resolved Hide resolved
python/nav/jwtconf.py Show resolved Hide resolved
Copy link
Member

@lunkwill42 lunkwill42 left a comment

Choose a reason for hiding this comment

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

Nice work! See my usual inline nitpicks.

I might have more, but I'll save them for later ;-)

python/nav/etc/jwt.conf Outdated Show resolved Hide resolved
python/nav/etc/jwt.conf Outdated Show resolved Hide resolved
python/nav/jwtconf.py Outdated Show resolved Hide resolved
python/nav/jwtconf.py Outdated Show resolved Hide resolved
@hmpf hmpf self-requested a review March 2, 2023 07:31
Copy link
Contributor

@hmpf hmpf left a comment

Choose a reason for hiding this comment

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

My nitpicks are resolved so it's up to @lunkwill42 now

python/nav/jwtconf.py Outdated Show resolved Hide resolved
@sonarcloud
Copy link

sonarcloud bot commented Mar 9, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@hmpf hmpf self-requested a review April 13, 2023 11:35
Copy link
Member

@lunkwill42 lunkwill42 left a comment

Choose a reason for hiding this comment

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

This is shaping up now, but there is a problem with how/when the configuration file is being read.

After a clean installation of NAV, many NAV commands (e.g. navdf) now spit out this error message (but continue working):

Error reading jwtconfig: Configuration error: Invalid 'name': 'name' must not be empty

Which is pretty confusing for anyone who hasn't even considered changing jwt.conf yet.

@stveit
Copy link
Contributor Author

stveit commented May 24, 2023

Updated so that local JWT config is optional. By default it is commented out, so to activate it you comment in the lines and fill in the correct values. + some other changes. So now error message for missing name etc will only show up if you actually have those lines active

@stveit stveit force-pushed the jwt-local-token-config branch from ff427ea to c856028 Compare May 24, 2023 10:07
@stveit stveit force-pushed the jwt-local-token-config branch from c856028 to 35079b7 Compare May 25, 2023 07:08
@sonarcloud
Copy link

sonarcloud bot commented May 25, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@stveit
Copy link
Contributor Author

stveit commented May 26, 2023

did a rebase on master to get tests passing. I have a branch with much cleaner commit log, but im keeping it as it is until its approved

@lunkwill42 lunkwill42 added the api label Aug 28, 2023
@stveit
Copy link
Contributor Author

stveit commented Aug 28, 2023

Instead of using the ConfigurationError exception for everyyhing, there should be subclasses for each specific thing that can go wrong

Copy link
Member

@lunkwill42 lunkwill42 left a comment

Choose a reason for hiding this comment

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

Good idea with the ConfigurationError wrapping :)

The one thing I remember holding back from my previous review is this: Generally, all the config that is specific to the web parts of NAV is located in the etc/webfront/ directory. IMHO, the jwt.conf file should probably be located there as well (otherwise, we should start looking at restructuring everything inside etc/webfront/, which is out of scope in this PR)

python/nav/jwtconf.py Outdated Show resolved Hide resolved
python/nav/jwtconf.py Show resolved Hide resolved
@lunkwill42
Copy link
Member

Instead of using the ConfigurationError exception for everyyhing, there should be subclasses for each specific thing that can go wrong

I would tend to agree. But I suggest doing that in a separate PR, rather than complicate and prolong this one :) Make an issue!

python/nav/jwtconf.py Outdated Show resolved Hide resolved
@sonarcloud
Copy link

sonarcloud bot commented Sep 4, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@stveit stveit merged commit 6ece6d3 into Uninett:master Sep 7, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants