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

NAS-127183 / 24.10 / Customer designated login banner #13892

Merged
merged 15 commits into from
Jul 3, 2024
Merged

Conversation

aiden3c
Copy link
Contributor

@aiden3c aiden3c commented Jun 17, 2024

Government systems require a login banner prior to being allowed to log in. In the ticket it was determined to reuse the motd as our banner.
This PR has the middleware portion of this ticket. On top of giving a public endpoint for motd, we also have our motd_before_login option, which updates our sshd configuration to show our MOTD prior to login. Our database string length has also been upped from 1024 to 4096 (DoD requires 1300 minimum to fit the bare minimum message).

@aiden3c aiden3c requested a review from a team June 17, 2024 18:35
@aiden3c aiden3c changed the title Nas 127183 Customer designated login banner Jun 17, 2024
@bugclerk bugclerk changed the title Customer designated login banner NAS-127183 / 24.10 / Customer designated login banner Jun 17, 2024
@bugclerk
Copy link
Contributor

@anodos325
Copy link
Contributor

Is there any reason to not just always display motd before login?

@aiden3c
Copy link
Contributor Author

aiden3c commented Jun 17, 2024

Is there any reason to not just always display motd before login?

On the WebUI it could get annoying to have a popup modal every single time you log in with the motd. For the SSH part, we could do that but might as well keep parity with the WebUI for that logic.

Copy link
Contributor

@yocalebo yocalebo left a comment

Choose a reason for hiding this comment

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

We can add an API test here pretty easily. Need to create a banner and then scrape ssh session to make sure the text you put actually shows up.

Can also test to make sure that you can put a banner <= 4096.

@yocalebo yocalebo requested a review from anodos325 June 18, 2024 14:26
@aiden3c
Copy link
Contributor Author

aiden3c commented Jun 18, 2024

Instead of parsing the SSH session, would verifying that the SSHd config contains the banner line be sufficient? As well as looking to see that the contents of /etc/motd is also what we just set.

Copy link
Contributor

@bmeagherix bmeagherix left a comment

Choose a reason for hiding this comment

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

It's usually a good idea to add a CI test. I see there are some MOTD tests already in test_480_system_advanced.py

@aiden3c
Copy link
Contributor Author

aiden3c commented Jun 21, 2024

Have a passing test!

@aiden3c
Copy link
Contributor Author

aiden3c commented Jun 21, 2024

Still have to go through and redo the DB migration so its revision hashes are correct

Doesn't look like any alembic changes were made actually, I was under the impression that this PR had DB changes.

Should be clear to just merge as is.

Copy link
Contributor

@yocalebo yocalebo left a comment

Choose a reason for hiding this comment

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

Hmm, I don't think adding a new db column is necessary. I'd rather keep this as simple as possible. We should just generate SSH to show the motd if one is set in the database. I don't want to have another boolean option that enables this functionality.

To summarize:

  1. if adv_motd is set, then generate ssh accordingly.
  2. let's not call it get_motd. This is actually being used as a login banner. So we can name it login_banner.
  3. return datastore.query, system.advanced, [], {'get': True})['adv_motd']

@aiden3c
Copy link
Contributor Author

aiden3c commented Jun 21, 2024

I added the checkbox as it was suggested in the ticket! The reasoning (from what I assume) is to prevent having a popup every single time you log in (although we could just have it show up on the login page in general, not as a modal, but then there's UI flow issues with large banners).
This is also to not suddenly start showing the MOTD for every user with it set (which would be just about everyone since we have a default "Welcome to TrueNAS").

@aiden3c aiden3c requested a review from yocalebo June 21, 2024 18:01
Copy link
Contributor

@anodos325 anodos325 left a comment

Choose a reason for hiding this comment

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

Login banner needs to be a separate etc file with entry in etc plugin defining permissions required. no_auth_required + roles still needs to be resolved.

@aiden3c
Copy link
Contributor Author

aiden3c commented Jun 28, 2024

@anodos325 how would we go about deleting the old /etc/login_banner if it's in its own mako? If exiting early stops the file from being written, then I could probably do a delete then exit early.

@anodos325
Copy link
Contributor

anodos325 commented Jun 28, 2024

@anodos325 how would we go about deleting the old /etc/login_banner if it's in its own mako? If exiting early stops the file from being written, then I could probably do a delete then exit early.

raise FileShouldNotExist within mako file (you will need to import from etc plugin)

@aiden3c
Copy link
Contributor Author

aiden3c commented Jun 28, 2024

@anodos325 I've implemented those changes! Is there any way to specify that when we're reloading the ssh service that we should etc generate our login_banner as well? Would save us a line in the config.py

@aiden3c aiden3c requested a review from anodos325 June 28, 2024 13:56
@aiden3c
Copy link
Contributor Author

aiden3c commented Jun 28, 2024

Login banner needs to be a separate etc file with entry in etc plugin defining permissions required. no_auth_required + roles still needs to be resolved.

I'm looking into this right now

@anodos325
Copy link
Contributor

@anodos325 I've implemented those changes! Is there any way to specify that when we're reloading the ssh service that we should etc generate our login_banner as well? Would save us a line in the config.py

If you put the login banner in the etc group for ssh then it will be generated every time etc.generate ssh is called.

@aiden3c
Copy link
Contributor Author

aiden3c commented Jun 28, 2024

The no_authz_required issue was me putting the accepts decorator above the no_authz_required, moving it below fixes it.

Should be good for final review now!

@@ -297,6 +297,7 @@ class EtcService(Service):
{'type': 'mako', 'path': 'pam.d/sshd', 'local_path': 'pam.d/sshd_linux'},
{'type': 'mako', 'path': 'local/users.oath', 'mode': 0o0600, 'checkpoint': 'pool_import'},
{'type': 'py', 'path': 'local/ssh/config'},
{'type': 'mako', 'path': 'login_banner', 'mode': 0o600},
Copy link
Contributor

Choose a reason for hiding this comment

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

Also need to add system.advanced.login_banner to ctx above so that we only query once and provide to all scripts in this group.

Still need to make sure the tests run fine though
@aiden3c aiden3c requested a review from yocalebo July 3, 2024 11:41
import os
import pytest
import sys
apifolder = os.getcwd()
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need to do this. Just need to import the relevant modules.

@aiden3c aiden3c requested a review from yocalebo July 3, 2024 11:54
Copy link
Contributor

@yocalebo yocalebo left a comment

Choose a reason for hiding this comment

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

Awesome, thanks!

@aiden3c aiden3c merged commit 5b61d3b into master Jul 3, 2024
2 of 3 checks passed
@aiden3c aiden3c deleted the NAS-127183 branch July 3, 2024 12:17
@bugclerk
Copy link
Contributor

bugclerk commented Jul 3, 2024

This PR has been merged and conversations have been locked.
If you would like to discuss more about this issue please use our forums or raise a Jira ticket.

@truenas truenas locked as resolved and limited conversation to collaborators Jul 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants