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

feat: Auto-Populate POSIX Information on sign in using SSO [CM-399] #9755

Merged
merged 20 commits into from
Aug 28, 2024

Conversation

kkunapuli
Copy link
Contributor

@kkunapuli kkunapuli commented Jul 29, 2024

Ticket

CM-399

Description

When the a determined master is configured to expected the POSIX claims in SSO login & they are provided in the claim, then we will populate the relevant fields for the user:

AgentUID   null.Int    `db:"agent_uid" json:"agent_uid"`
AgentGID   null.Int    `db:"agent_gid" json:"agent_gid"`
AgentUser  null.String `db:"agent_user" json:"agent_user"`
AgentGroup null.String `db:"agent_group" json:"agent_group"`

Also re-adds new fields to master configuration (original done here https://github.com/determined-ai/determined/pull/9690/files). The original PR was reverted because of CI errors.

Test Plan

Test using an Okta application.

OIDC

Recommended application: carolina-oidc-test, https://dev-2564556-admin.okta.com/admin/app/oidc_client/instance/0oacxxzecx7a9l5O85d7/#tab-general

  • add your user to the test application, filling in the fields posix_uid (int), posix_gid (int), agent_user_name (string) and agent_group_name (string)
  • in your master config, add the following fields to an oidc section:
oidc:
  agent_uid_attribute_name: posix_uid
  agent_gid_attribute_name: posix_gid
  agent_user_name_attribute_name: agent_user_name
  agent_group_name_attribute_name: agent_group_name
  always_redirect: true
  • start devcluster, and log in using Okta
  • inspect the database and ensure that it is updated, e.g. SELECT * FROM agent_user_groups; and look at columns uid, gid, user_ and group_

You can also try different combinations! A user should be able to specify any, none, or all of the new parameters.

SAML

Recommended application: Determined SAML CI, https://dev-2564556-admin.okta.com/admin/app/dev-2564556_determinedsamlci_1/instance/0oaganmj6zxHC3A575d7/#tab-assignments

  • add your user to the test application, the fields will be filled out automatically
  • in your master config, add the following fields to an saml section:
saml:
  agent_uid_attribute_name: posix_uid
  agent_gid_attribute_name: posix_gid
  agent_user_name_attribute_name: agent_user_name
  agent_group_name_attribute_name: agent_group_name
  always_redirect: true
  • start devcluster, and log in using Okta
  • inspect the database and ensure that it is updated, e.g.
determined=# select * from agent_user_groups;
 id | user_id |  user_   | uid |  group_  | gid 
----+---------+----------+-----+----------+-----
  2 |       3 | Kristine |   4 | Kunapuli |   5

user_ will be your first name and group_ will be your last name.

Checklist

  • Changes have been manually QA'd
  • New features have been approved by the corresponding PM
  • User-facing API changes have the "User-facing API Change" label
  • Release notes have been added as a separate file under docs/release-notes/
    See Release Note for details.
  • Licenses have been included for new code which was copied and/or modified from any external code

@cla-bot cla-bot bot added the cla-signed label Jul 29, 2024
@kkunapuli kkunapuli changed the title feat: automatically populate posix fields feat: automatically populate posix fields from master config Jul 29, 2024
Copy link

netlify bot commented Jul 29, 2024

Deploy Preview for determined-ui canceled.

Name Link
🔨 Latest commit bdd7865
🔍 Latest deploy log https://app.netlify.com/sites/determined-ui/deploys/66bb9493a3038e0008e6832a

strAgentUID := getSAMLAttribute(response, string(s.userConfig.agentUIDAttributeName))
tempAgentUID, err := strconv.Atoi(strAgentUID)
if err != nil {
logrus.WithError(err).WithField("agentUID", strAgentUID).Error("unable to convert to integer")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this error should be very rare / surprising but we should log it just in case.

Copy link
Contributor

Choose a reason for hiding this comment

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

wdy think about having this parser return an err? the only place it's used does support returning an error that might be the right behavior here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea, thanks!

Copy link

codecov bot commented Jul 29, 2024

Codecov Report

Attention: Patch coverage is 37.96296% with 67 lines in your changes missing coverage. Please review.

Project coverage is 54.04%. Comparing base (4e47a1e) to head (bdd7865).
Report is 64 commits behind head on main.

Files Patch % Lines
master/internal/plugin/oidc/service.go 0.00% 47 Missing ⚠️
master/internal/plugin/saml/service.go 68.42% 18 Missing ⚠️
master/internal/user/postgres_agentusergroup.go 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9755      +/-   ##
==========================================
- Coverage   54.31%   54.04%   -0.27%     
==========================================
  Files        1261     1261              
  Lines      155624   155714      +90     
  Branches     3534     3533       -1     
==========================================
- Hits        84530    84159     -371     
- Misses      70956    71417     +461     
  Partials      138      138              
Flag Coverage Δ
backend 44.89% <37.96%> (-0.02%) ⬇️
harness 71.25% <ø> (-1.37%) ⬇️
web 53.79% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
master/internal/config/oidc_config.go 50.00% <ø> (ø)
master/internal/config/saml_config.go 20.00% <ø> (ø)
master/internal/user/postgres_agentusergroup.go 86.04% <50.00%> (-3.96%) ⬇️
master/internal/plugin/saml/service.go 32.99% <68.42%> (+12.21%) ⬆️
master/internal/plugin/oidc/service.go 7.17% <0.00%> (-1.64%) ⬇️

... and 19 files with indirect coverage changes

if err != nil {
if err == sql.ErrNoRows {
logrus.WithError(err).Warnf("no agent user group results from workspaceID=%d", workspaceID)
} else if err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

workspaceID is supposed to be optional, but bun throws an error if zero results are returned.

@determined-ci determined-ci added the documentation Improvements or additions to documentation label Jul 30, 2024
@determined-ci determined-ci requested a review from a team July 30, 2024 20:17
@kkunapuli kkunapuli changed the title feat: automatically populate posix fields from master config feat: Auto-Populate POSIX Information on sign in using SSO [CM-399] Jul 30, 2024
`agent_gid_attribute_name`, `agent_user_name_attribute_name`, or
`agent_group_name_attribute_name`. Please visit :ref:`oidc master configuration
<_master-config-oidc>` or :ref:`saml master configuration <_master-config-saml>` for details. If
any of the fields are configured, they will be used and synced to the database.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand why it's accepting _master-config-saml as a reference link but not _master-config-oidc.

Copy link
Member

Choose a reason for hiding this comment

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

:orphan:

New Features

  • Master Configuration: Add support for POSIX claims in the master configuration. It now accepts
    agent_uid_attribute_name, agent_gid_attribute_name, agent_user_name_attribute_name,
    or agent_group_name_attribute_name. Refer to the :ref:OIDC master configuration <master-config-oidc>
    or :ref:SAML master configuration <master-config-saml> for details. If any of these fields
    are configured, they will be used and synced to the database.

Copy link
Member

Choose a reason for hiding this comment

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

@kkunapuli i think maybe you added the leading underscore and its that part that is not needed. maybe something with the angle brackets. https://docs.readthedocs.io/en/stable/guides/cross-referencing-with-sphinx.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was it - thank you so much @tara-det-ai!

@kkunapuli kkunapuli force-pushed the kunapuli/auto-populate-posix-info2 branch from dead50d to edf0afb Compare July 30, 2024 20:43
@kkunapuli kkunapuli marked this pull request as ready for review July 31, 2024 17:23
@kkunapuli kkunapuli requested a review from a team as a code owner July 31, 2024 17:23
@kkunapuli kkunapuli requested a review from hamidzr July 31, 2024 17:23
Copy link
Member

@tara-det-ai tara-det-ai left a comment

Choose a reason for hiding this comment

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

docs stamp not required to merge; left a suggested edit

strAgentUID := getSAMLAttribute(response, string(s.userConfig.agentUIDAttributeName))
tempAgentUID, err := strconv.Atoi(strAgentUID)
if err != nil {
logrus.WithError(err).WithField("agentUID", strAgentUID).Error("unable to convert to integer")
Copy link
Contributor

Choose a reason for hiding this comment

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

wdy think about having this parser return an err? the only place it's used does support returning an error that might be the right behavior here.

@determined-ci determined-ci requested a review from a team August 6, 2024 19:06
@kkunapuli kkunapuli force-pushed the kunapuli/auto-populate-posix-info2 branch from 140ef56 to f9258b7 Compare August 6, 2024 19:58
Copy link
Member

@varlogtim varlogtim left a comment

Choose a reason for hiding this comment

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

Possible concern.

Copy link
Member

@varlogtim varlogtim left a comment

Choose a reason for hiding this comment

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

Possible issue

master/internal/plugin/oidc/service.go Outdated Show resolved Hide resolved
@kkunapuli kkunapuli force-pushed the kunapuli/auto-populate-posix-info2 branch from f9258b7 to 5800ffe Compare August 7, 2024 14:12
Group: dbData.Group,
}

if sessionData.AgentUIDSet {
Copy link
Member

@varlogtim varlogtim Aug 7, 2024

Choose a reason for hiding this comment

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

Another nit with this pattern.

I am imagining the following UX:

TL;DR: once a user as a UID/GID set, it can never be unset via Auth claims and would need to be manually removed.

  1. System admin configures security.default_task.user_id: 1234, in master.yaml
  2. Some impetus: results in UserA having AgentUID 5432 being set in the auth claim.
  3. Other impetus: results in UserA's AgentUID being removed from the auth claim for which the admin would expect that tasks run by that user would run as UID 1234, however, I suspect they will continue to run as 5432.

To be clear, I am OK with this behavior, I think... but I wanted to bring it up here for the following reasons:

  1. To get confirmation that what I speculation about the behavior here is correct.
  2. Document that this is the behavior we should expect.
  3. Get any input from folks other than me if this behavior is acceptable.

Copy link
Member

@varlogtim varlogtim Aug 8, 2024

Choose a reason for hiding this comment

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

I tested this behavior today and confirmed that it works as I expected it might.

Once you have enabled this feature and an AgentUID/GID is set for a user in order to have have this revert back to using the security.default_task.uid an admin needs to manually remove the AgentUID/GID settings for that user.

We discussed real would situations in which this type of thing could come and yesterday and the only real one we could think is if a customer switches IdPs and forgets to populate the Agent UID/GID attributes in the auth claim. In this situation we would likely want to keep the UID and GID of the users there and not remove them and have the system go back to user the default. Therefore, I think the current behavior is best.

reset manually. In order to have have the UID or GID revert back to using the
security.default_task.uid(gid), an admin needs to manually remove the agent UID/GID settings for
that user.

Copy link
Member

Choose a reason for hiding this comment

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

To automatically link custom claims, you can configure the attribute name with the relevant field. For example:

agent_uid_attribute_name: "custom_uid_attribute_name"

.. note::

Once this feature is enabled and an agent UID/GID is assigned to a user, it can only be reset manually.
To revert the UID or GID back to the default value specified by security.default_task.uid(gid), an admin
must manually remove the agent UID/GID settings for that user.

Copy link
Member

@tara-det-ai tara-det-ai left a comment

Choose a reason for hiding this comment

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

suggested edit

@determined-ci determined-ci requested a review from a team August 13, 2024 17:15
@kkunapuli kkunapuli merged commit c1b7767 into main Aug 28, 2024
82 of 96 checks passed
@kkunapuli kkunapuli deleted the kunapuli/auto-populate-posix-info2 branch August 28, 2024 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants