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

Unique repo path and permissions #8517

Merged
merged 6 commits into from
Feb 24, 2022

Conversation

alexmt
Copy link
Collaborator

@alexmt alexmt commented Feb 15, 2022

Signed-off-by: Alexander Matyushentsev AMatyushentsev@gmail.com

PR implements two changes:

  • Git and Helm repositories are cloned/fetched into random/non-predicable local directory
  • Repo server remove read permissions from Git repos when not using it for manifest generation

@alexmt alexmt added this to the v2.3 milestone Feb 15, 2022
@codecov
Copy link

codecov bot commented Feb 15, 2022

Codecov Report

Merging #8517 (74001dd) into master (ac47a42) will decrease coverage by 0.01%.
The diff coverage is 50.52%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8517      +/-   ##
==========================================
- Coverage   42.60%   42.59%   -0.02%     
==========================================
  Files         176      183       +7     
  Lines       22941    23102     +161     
==========================================
+ Hits         9774     9840      +66     
- Misses      11770    11853      +83     
- Partials     1397     1409      +12     
Impacted Files Coverage Δ
cmd/argocd/commands/app.go 0.53% <0.00%> (ø)
pkg/apis/application/v1alpha1/repository_types.go 60.52% <0.00%> (ø)
util/git/creds.go 9.80% <4.34%> (-0.20%) ⬇️
reposerver/askpass/server.go 35.29% <35.29%> (ø)
util/helm/client.go 45.14% <55.55%> (-3.37%) ⬇️
reposerver/repository/repository.go 58.49% <55.93%> (-0.18%) ⬇️
util/io/paths.go 68.75% <68.75%> (ø)
util/grpc/sanitizer.go 85.00% <85.00%> (ø)
reposerver/repository/lock.go 100.00% <100.00%> (ø)
util/git/client.go 44.74% <100.00%> (ø)
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 764b7a6...74001dd. Read the comment docs.

@alexmt alexmt force-pushed the unique-repo-path-and-permissions branch 2 times, most recently from 958041d to 81f7df8 Compare February 16, 2022 17:30
Copy link
Member

@crenshaw-dev crenshaw-dev left a comment

Choose a reason for hiding this comment

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

LGTM!

@alexmt alexmt force-pushed the unique-repo-path-and-permissions branch from 81f7df8 to 7cecf78 Compare February 18, 2022 17:27
Copy link
Member

@crenshaw-dev crenshaw-dev left a comment

Choose a reason for hiding this comment

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

Should we go ahead an use the UUIDv4 path generator for this line, too?

file, err := ioutil.TempFile("", "values-*.yaml")

@alexmt
Copy link
Collaborator Author

alexmt commented Feb 22, 2022

@crenshaw-dev request about file, err := ioutil.TempFile("", "values-*.yaml") already implemented in another PR

Copy link
Member

@crenshaw-dev crenshaw-dev left a comment

Choose a reason for hiding this comment

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

One small comment.

return "", err
}
tempDir := path.Join(os.TempDir(), newUUID.String())
if err := os.Mkdir(tempDir, 0755); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need 755? Or just 700?

util/grpc/sanitizer.go Outdated Show resolved Hide resolved
Comment on lines 69 to 72
for k, v := range s.replacements {
val = strings.Replace(val, k, v, -1)
}
return val
Copy link
Member

@jessesuen jessesuen Feb 22, 2022

Choose a reason for hiding this comment

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

Rather than maintain the map everytime we clone a repo, I feel we could have a regexp replace this

func NewSanitizer(root string) {
	return &sanitizer{
		re: regexp.MustCompile(`(` + root + `/.*?)/`) // non-greedy until next slash after root
	}
}

func (s *sanitizer) Replace(val string) string {
    return s.re.ReplaceAllString(val, ".")
}

Copy link
Member

@crenshaw-dev crenshaw-dev Feb 22, 2022

Choose a reason for hiding this comment

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

To avoid missing relative paths, we could add a reasonably-unique prefix to the temp dir name and use a regex like this:

no-log-[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}

(The end is just a regex for UUIDv4.)

Copy link
Member

Choose a reason for hiding this comment

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

Another benefit of a keyword-based replace would be that random paths outside the repo dir (like temporary values.yaml files' paths) could be sanitized as well.

empDir := path.Join(os.TempDir(), fmt.Sprintf("no-log-%s", newUUID.String()))

Copy link
Member

@crenshaw-dev crenshaw-dev Feb 22, 2022

Choose a reason for hiding this comment

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

Both approaches also help us completely avoid an attack where someone uses the sanitizer to leak valid paths by forcing errors containing lots of UUIDs. I think that attack is super impractical, but if we can solve two problems at once, great.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

New "sanitizer" is created and deleted every request. So this map will get 2~3 entries max.

Using the gprc interceptor and context was the least intrusive way to introduce sanitization. I really did not want to introduce a lot of copy-paste code. So it forced me to make sanitizer pretty generic . I think regex based sanitization will be useful. Implemented option suggested by @jessesuen because it is less coupled with how we generate unique paths .

Copy link
Member

@jessesuen jessesuen left a comment

Choose a reason for hiding this comment

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

I see that we sanitize the gRPC responses, but does this change sanitize the log outputs as well? Or do we not care?

…cation

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
…in active use

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
…tory; change repo directory permissions

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
@alexmt alexmt force-pushed the unique-repo-path-and-permissions branch from 7cecf78 to ec2e2c4 Compare February 23, 2022 02:30
Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
@alexmt alexmt force-pushed the unique-repo-path-and-permissions branch from ec2e2c4 to 278b27b Compare February 23, 2022 18:43
@alexmt alexmt force-pushed the unique-repo-path-and-permissions branch from 8687c23 to 4a1f628 Compare February 24, 2022 18:22
Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
@alexmt alexmt force-pushed the unique-repo-path-and-permissions branch from 4a1f628 to 74001dd Compare February 24, 2022 18:31
Copy link
Member

@jessesuen jessesuen left a comment

Choose a reason for hiding this comment

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

This looks a lot simpler than before. Thanks!

@alexmt alexmt merged commit c7da148 into argoproj:master Feb 24, 2022
@alexmt alexmt deleted the unique-repo-path-and-permissions branch February 24, 2022 19:45
alexmt added a commit that referenced this pull request Feb 25, 2022
Unique repo path and permissions (#8517)

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
wojtekidd pushed a commit to wojtekidd/argo-cd that referenced this pull request Apr 25, 2022
Unique repo path and permissions (argoproj#8517)

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
Signed-off-by: wojtekidd <wojtek.cichon@protonmail.com>
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.

4 participants