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

[analyze] Add Analyzer interface for Gitlab #3232

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

abmussani
Copy link
Contributor

Description:

This PR implements the analyzer interface for Gitlab.

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

@abmussani abmussani requested review from a team as code owners August 19, 2024 15:58
Copy link
Collaborator

@mcastorina mcastorina left a comment

Choose a reason for hiding this comment

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

The code looks good but the test isn't passing. It looks like the gitlab token is expired:

» curl 'https://gitlab.com/api/v4/personal_access_tokens/self' -H "Private-Token: $GITLAB_TOKEN"
{
  "error": "invalid_token",
  "error_description": "Token is expired. You can either do re-authorization or token refresh."
}

to make more unique FullyQualifiedName, Ids are added for resources.
@abmussani
Copy link
Contributor Author

@mcastorina I have updated the active gitlab key in vault. Also There are some changes to make resource unique. Re-requesting this PR to get view

Bindings: []analyzers.Binding{},
}

// Add token and it's permissions to bindings
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we sure token should be a resource here? Does the credential we're analyzing grant permission to perform actions on the token?

// Add token and it's permissions to bindings
tokenResource := analyzers.Resource{
Name: info.AccessToken.Name,
FullyQualifiedName: fmt.Sprintf("github.com/token/%d", info.AccessToken.ID),
Copy link
Collaborator

Choose a reason for hiding this comment

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

"github.com" should probably be "gitlab.com" here

FullyQualifiedName: fmt.Sprintf("github.com/token/%d", info.AccessToken.ID),
Type: "access_token",
Metadata: map[string]any{
"last_used_at": info.AccessToken.LastUsedAt,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we don't update resources, this value can easily become stale. I think it's best to remove it.

for _, project := range info.Projects {
projectResource := analyzers.Resource{
Name: project.NameWithNamespace,
FullyQualifiedName: fmt.Sprintf("github.com/project/%d", project.ID),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here github.com -> gitlab.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants