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

WIP: Add user group membership check to decide upstream host - yaml plugin #425

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

eesaanatluri
Copy link

@eesaanatluri eesaanatluri commented Aug 12, 2024

We are using the sshpiper yaml plugin for our use case, where we are trying to upgrade our parallel filesystem and migrate users from the older version to the newer version. We want to control which login nodes in the cluster the user can SSH to, based on their data migration status. Doing this for each user is not feasible.

A user-facing proxy VM installed with sshpiper is dedicated to deciding the user's target host to log in.

Our idea was to assign users special Unix groups, (for example group_A and group_B based on their migration status), and route their SSH connections to different login nodes according to their group membership. If they are in group_A they are routed to the login_node_A and if they are in group_B they are routed to the login_node_B

To achieve this, we added functionality to the sshpiper yaml plugin so that there is also an option to route users based on group membership.

This PR lets us define a groupname in place of a username in the config file (sshpiperd.yaml) for the yaml plugin to route users based on a Unix group membeship

If the username is not defined in the config file, it checks for groupname and decides their target host upstream.
If the username is defined it goes with the target host upstream, defined for the user. So the original functionality is still intact and we have an additional feature to add groupname in place of username to the config file, if we are dealing with large number of users.

Example sshpiperd.yaml

version: "1.0"
pipes:
# username-based routing 
- from:
    - username: "alice"
      authorized_keys: /home/alice/.ssh/authorized_keys
  to:
    host: login002
    username: "alice"
    private_key: /home/alice/.ssh/id_ecdsa
    ignore_hostkey: true

# groupname-based routing
# key auth
- from:
    - groupname: "group_A" # catch all
      authorized_keys: /home/$DOWNSTREAM_USER/.ssh/authorized_keys
  to:
    host: login001
    ignore_hostkey: true
    private_key: /home/$DOWNSTREAM_USER/.ssh/id_ecdsa
- from:
    - groupname: "group_B" # catch all
      authorized_keys: /home/$DOWNSTREAM_USER/.ssh/authorized_keys
  to:
    host: login002
    ignore_hostkey: true
    private_key: /home/$DOWNSTREAM_USER/.ssh/id_ecdsa

# Password auth when no key is defined.
- from:
    - groupname: "group_A"
  to:
    host: login001
    ignore_hostkey: true
- from:
    - groupname: "group_B"
  to:
    host: login002
    ignore_hostkey: true

…he upstream

If a username is not given in the yaml config file it parses the groupname and
checks if user is part of that group and routes them accordinly to the
associated host defined in the config file for the yaml plugin
@eesaanatluri eesaanatluri changed the title Add group membership check for a user to decide upstream host Draft: Add group membership check for a user to decide upstream host Aug 12, 2024
@eesaanatluri eesaanatluri changed the title Draft: Add group membership check for a user to decide upstream host Draft: Add user group membership check to decide upstream host - yaml plugin Aug 12, 2024
@eesaanatluri
Copy link
Author

Hi @tg123 Looking for some feedback.

Copy link
Owner

@tg123 tg123 left a comment

Choose a reason for hiding this comment

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

i am ok with group look up
will it introduce some security concerns like timing attack?

@@ -220,20 +223,30 @@ func (p *plugin) createUpstream(conn libplugin.ConnMetadata, to pipeConfigTo, or

func (p *plugin) findAndCreateUpstream(conn libplugin.ConnMetadata, password string, publicKey []byte) (*libplugin.Upstream, error) {
user := conn.User()
userGroups, err := getUserGroups(user)
Copy link
Owner

Choose a reason for hiding this comment

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

read group only when from.Groupname is not empty?

so, any group err will not block the original process

@tg123
Copy link
Owner

tg123 commented Aug 15, 2024

rebase plz

@eesaanatluri
Copy link
Author

I will rebase. I will also fix test cases so they pass the checks for unit tests and E2E.

@eesaanatluri eesaanatluri changed the title Draft: Add user group membership check to decide upstream host - yaml plugin WIP: Add user group membership check to decide upstream host - yaml plugin Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants