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] Authenticated agent #1247

Draft
wants to merge 8 commits into
base: feature/authenticated-microservices
Choose a base branch
from

Conversation

petertrr
Copy link
Member

@petertrr petertrr commented Sep 19, 2022

(partially TODO):

  • Run tested tool as a dedicated user save-executor
  • Authorize requests from save-agent using ServiceAccount token
  • Create a NetworkPolicy that would restrict network access of save-agent pods only to orchestrator (only main port, not the management one), kube-dns and the Internet

Closes #1049

* NetworkPolicy to allow egress only to orchestrator, kube-dns and the Internet from save-agent pods
* Don't automount ServiceAccount token into save-agent pods
* Field `Agent.isAuthenticated`
@nulls
Copy link
Member

nulls commented Mar 20, 2023

@sanyavertolet, a good enhancement for save-demo-agent too

@sanyavertolet
Copy link
Member

@sanyavertolet, a good enhancement for save-demo-agent too

Totally agree, will take a look

# Conflicts:
#	save-cloud-common/src/jvmMain/kotlin/com/saveourtool/save/entities/Agent.kt
Comment on lines 16 to 20
RUN groupadd --gid 1100 save-agent && \
groupadd --gid 1200 save-executor && \
useradd --uid 1100 --gid 1100 --create-home --shell /bin/sh save-agent && \
useradd --uid 1200 --gid 1100 --create-home --shell /bin/sh save-agent && \
usermod -aG save-executor save-agent && \
Copy link
Member

Choose a reason for hiding this comment

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

I cannot understand why do we create a new user and remove the key from the pod?
As far as I can see, there are two ways:

  1. Leave the key in /var/run/secrets/kubernetes.io/serviceaccount/token and forbid the child process of save-agent accessing it (probably create another user as you do here);
  2. Forget about Unix permission system and delegate token management to orchestrating pod.

To my mind second way brings less problems as in case of orchestrator sending token to agent might cause problems with save-demo-agent (it has ktor server running and so we might need to implement auth for ktor server also). What was your idea?

Sorry for bothering and thanks in advance

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem with the second approach is that you'd need to reliably detect requests from not-yet-authorized agents and distinguish them from similar requests from a tested tool. One idea (I believe, that's why I've added Agent.isAuthenticated) was to initialize agents with isAuthenticated = false, then these agents would send request for a token (which they would do strictly before starting a tested tool), orchestrator would update isAuthenticated = true and won't return token for any new requests from this agent. However, there is no guarantee that already running tool will be able to mimic as a newly created agent and get the token.
That's why the first approach seemed more viable: The agent would read token from a file, that has restricted access for a user, that runs a tested tool.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks! Now I got the idea

### What's done:
 * Made save-agent run tested tool under save-executor user
 * Made save-demo-agent run demo tool under save-executor user
 * Added parentUserName and childUserName to agents configuration
 * Added token key protection if parentUserName is provided
@sanyavertolet sanyavertolet changed the base branch from master to feature/authenticated-microservices April 6, 2023 15:32
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.

Restrict network access of the executed tool
3 participants