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: implement server side filters for agents #3539

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

6543
Copy link
Member

@6543 6543 commented Mar 23, 2024

will allow #267, #1816 etc ...

TODOs:

  • API to set server-side-agent-filters
  • api to register agent for org
  • WebUI
  • secure all rpc endpoints
  • secure set of labels for non-admins

will allow woodpecker-ci#267

TODOs: API to set server-side-agent-filters; WebUI; secure all rpc endpoints; secure set of labels for non-admins
@6543 6543 added server feature add new functionality labels Mar 23, 2024
@anbraten
Copy link
Member

Nice.

One step would be to add orgId: <orgId>, repoId: <repoId> labels, so we can later on filter by that context, so an agent could be registered for a repo, org or the whole instance.

@6543
Copy link
Member Author

6543 commented Mar 24, 2024

☝️ that's the idea ... I just wrote down my starting point while chating @ c-base in berling ... and my ideas after brainstorming :D

this will take shape next week(s^tm)

anbraten
anbraten previously approved these changes Mar 26, 2024
server/model/agent.go Outdated Show resolved Hide resolved
@@ -187,7 +187,6 @@ func run(c *cli.Context, backends []types.Backend) error {
"hostname": hostname,
"platform": engInfo.Platform,
"backend": backendEngine.Name(),
"repo": "*", // allow all repos by default
Copy link
Member

Choose a reason for hiding this comment

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

Might be a breaking change as agent owners were allowed to filter for repos as well. We could solve this by adding the new enforced filters with sth like internal_repo_id and internal_org_id and leave repo untouched

@anbraten anbraten dismissed their stale review March 26, 2024 10:51

by accident

@anbraten anbraten marked this pull request as draft March 28, 2024 07:46
@anbraten
Copy link
Member

anbraten commented Apr 17, 2024

@6543 I've added a commit with the enforced labels and checks I had in mind. What do you think about that approach?

Comment on lines +113 to +134
workflowID, err := strconv.ParseInt(id, 10, 64)
if err != nil {
return err
}

workflow, err := s.store.WorkflowLoad(workflowID)
if err != nil {
log.Error().Err(err).Msgf("rpc.update: cannot find workflow with id %d", workflowID)
return err
}

currentPipeline, err := s.store.GetPipeline(workflow.PipelineID)
if err != nil {
log.Error().Err(err).Msgf("cannot find pipeline with id %d", workflow.PipelineID)
return err
}

repo, err := s.store.GetRepo(currentPipeline.RepoID)
if err != nil {
log.Error().Err(err).Msgf("cannot find repo with id %d", currentPipeline.RepoID)
return err
}
Copy link
Member

Choose a reason for hiding this comment

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

I've added quite a few selects to simply get the repo atm.

Comment on lines +35 to +36
// Server side enforced agent filters
Filters map[string]string `json:"filters" xorm:"'filters' json"`
Copy link
Member

Choose a reason for hiding this comment

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

What kind of filters do you have in mind that should be set through the UI instead of the labels env variable config of the agent itself?

Comment on lines +57 to +63
if a.IsSystemAgent() {
filters["org-id"] = "*" // allow all orgs
filters["repo-id"] = "*" // allow all repos
} else if a.OrgID > 0 {
filters["org-id"] = fmt.Sprintf("%d", a.OrgID)
filters["repo-id"] = "*" // allow all repos of the org
}
Copy link
Member

Choose a reason for hiding this comment

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

This is what I had in mind to set agent access labels by filters ☝🏾

@@ -57,6 +57,13 @@ func queuePipeline(ctx context.Context, repo *model.Repo, pipelineItems []*stepb
return server.Config.Services.Queue.PushAtOnce(ctx, tasks)
}

func enforcedLabels(task *model.Task, repo *model.Repo) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func enforcedLabels(task *model.Task, repo *model.Repo) {
func enforceLabels(task *model.Task, repo *model.Repo) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature add new functionality server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants