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

Check that a user belongs to the correct SHM domain when registering with an SRE #2292

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from

Conversation

craddm
Copy link
Contributor

@craddm craddm commented Nov 14, 2024

…with SRE

✅ Checklist

  • You have given your pull request a meaningful title (e.g. Enable foobar integration rather than 515 foobar).
  • You are targeting the appropriate branch. If you're not certain which one this is, it should be develop.
  • Your branch is up-to-date with the target branch (it probably was when you started, but it may have changed since then).

🚦 Depends on

⤴️ Summary

Adds a check of the user's principal name when registering with an SRE. If the domain in the principal name does not match the FQDN of the SHM that the SRE is linked to, the user will not be added to the SRE's security group and an error will be printed explaining why.

Example output:
image

🌂 Related issues

Relates to #2275

Does not close #2275, as that also encompasses the add command, whereas this PR only handles registering users

🔬 Tests

Tested locally

Copy link

github-actions bot commented Nov 14, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  data_safe_haven/administration/users
  entra_users.py
  research_user.py
  user_handler.py
  data_safe_haven/commands
  users.py 164
Project Total  

This report was generated by python-coverage-comment-action

@craddm craddm changed the base branch from release-v5.1.0 to develop November 18, 2024 10:58
@craddm craddm marked this pull request as ready for review November 26, 2024 15:49
@craddm craddm requested a review from a team as a code owner November 26, 2024 15:49
@craddm craddm changed the title [WIP] Check that a user belongs to the correct SHM domain when registering with an SRE Check that a user belongs to the correct SHM domain when registering with an SRE Nov 26, 2024
Copy link
Member

@JimMadge JimMadge left a comment

Choose a reason for hiding this comment

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

Looks good, a suggestion and a couple of questions 👍.

Comment on lines +159 to +163
logger.error(
f"User [green]'{username}'[/green]'s principal domain name is [blue]'{user_domain}'[/blue].\n"
f"SRE [yellow]'{sre}'[/yellow] belongs to SHM domain [blue]'{shm_config.shm.fqdn}'[/blue].\n"
"The user's principal domain name must match the domain of the SRE to be registered."
)
Copy link
Member

Choose a reason for hiding this comment

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

I think we've had problems with multi-line log messages before (although we might strip those characters). Could you check the output?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like this in the log file:
image

Seems fine to me

Copy link
Member

Choose a reason for hiding this comment

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

The problem there is we have lines in the log file which are not in the log format which will make it difficult to parse.

We could,

  • Join the lines in the log file
  • Make each of these a different message
  • Put this output to stdout but a shorter summary to the log

Comment on lines +167 to +168
f"Username '{username}' does not belong to this Data Safe Haven deployment.\n"
"Please use 'dsh users add' to create this user."
Copy link
Member

Choose a reason for hiding this comment

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

Also here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In review
Development

Successfully merging this pull request may close these issues.

Existing users domains not matching when added
2 participants