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

Lets to get security credentials if run on AWS FarGate #2174

Closed
wants to merge 3 commits into from
Closed

Lets to get security credentials if run on AWS FarGate #2174

wants to merge 3 commits into from

Conversation

petlitskiy
Copy link

PMM-0

Link to the Feature Build: SUBMODULES-0

If this PR adds or removes or alters one or more API endpoints, please review and add or update the relevant API documents as well:

  • API Docs updated

If this PR is related to some other PRs in this or other repositories, please provide links to those PRs:

  • Links to related pull requests (optional).

@petlitskiy petlitskiy requested a review from a team as a code owner May 24, 2023 10:00
@petlitskiy petlitskiy requested review from JiriCtvrtka and PavelKhripkov and removed request for a team May 24, 2023 10:00
@it-percona-cla
Copy link

it-percona-cla commented May 24, 2023

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ petlitskiy
❌ anonymous


anonymous seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Member

@BupycHuk BupycHuk left a comment

Choose a reason for hiding this comment

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

Hi @petlitskiy,
thank you for your contribution.

Could you please sign the CLA, add to description what this PR is about and how it will help you?

I left a few comments what can be improved

Thank you

Comment on lines 143 to 151
p, err := procfs.NewProc(1)
if err != nil {
log.Fatalf("could not get process: %s", err)
}

envs, err := p.Environ()
if err != nil {
log.Fatalf("could not get process stat: %s", err)
}
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
p, err := procfs.NewProc(1)
if err != nil {
log.Fatalf("could not get process: %s", err)
}
envs, err := p.Environ()
if err != nil {
log.Fatalf("could not get process stat: %s", err)
}
env := os.Environ()
if err != nil {
log.Fatalf("could not get process stat: %s", err)
}

@@ -65,6 +71,16 @@ func mergeLabels(node *models.Node, agent *models.Agent) (model.LabelSet, error)
return res, nil
}

func contains(s []string, str string) string {
for _, v := range s {
match, err := regexp.MatchString(str, v)
Copy link
Member

Choose a reason for hiding this comment

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

It can be replaced with just strings.HasPrefix

log.Fatalf("could not get process stat: %s", err)
}

result := contains(envs, "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI.*")
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 know the exact environment variable? we can use os.GetEnv for it

Copy link
Author

@petlitskiy petlitskiy May 25, 2023

Choose a reason for hiding this comment

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

The exactly env variable ("AWS_CONTAINER_CREDENTIALS_RELATIVE_URI") ALWAYS is present only on AWS Fargate for PID 1 - i.e. only for "supervisord" process. It not available for "managed" process - that is why i use procfs but not os.GetEnv(). It is my opinion.

Copy link
Author

Choose a reason for hiding this comment

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

But yes - we can use os.GetEnv. I checked. It works well.

Comment on lines 155 to 180
if result != "" {
return &agentpb.SetStateRequest_AgentProcess{
Type: inventorypb.AgentType_RDS_EXPORTER,
TemplateLeftDelim: tdp.Left,
TemplateRightDelim: tdp.Right,
Args: args,
Env: []string{
fmt.Sprintf("AWS_CONTAINER_CREDENTIALS_RELATIVE_URI=%s", result),
},
TextFiles: map[string]string{
"config": "---\n" + string(b),
},
RedactWords: words,
}, nil
} else {
return &agentpb.SetStateRequest_AgentProcess{
Type: inventorypb.AgentType_RDS_EXPORTER,
TemplateLeftDelim: tdp.Left,
TemplateRightDelim: tdp.Right,
Args: args,
TextFiles: map[string]string{
"config": "---\n" + string(b),
},
RedactWords: words,
}, nil
}
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
if result != "" {
return &agentpb.SetStateRequest_AgentProcess{
Type: inventorypb.AgentType_RDS_EXPORTER,
TemplateLeftDelim: tdp.Left,
TemplateRightDelim: tdp.Right,
Args: args,
Env: []string{
fmt.Sprintf("AWS_CONTAINER_CREDENTIALS_RELATIVE_URI=%s", result),
},
TextFiles: map[string]string{
"config": "---\n" + string(b),
},
RedactWords: words,
}, nil
} else {
return &agentpb.SetStateRequest_AgentProcess{
Type: inventorypb.AgentType_RDS_EXPORTER,
TemplateLeftDelim: tdp.Left,
TemplateRightDelim: tdp.Right,
Args: args,
TextFiles: map[string]string{
"config": "---\n" + string(b),
},
RedactWords: words,
}, nil
}
var env []string
if result != "" {
env = []string{fmt.Sprintf("AWS_CONTAINER_CREDENTIALS_RELATIVE_URI=%s", result)}
}
return &agentpb.SetStateRequest_AgentProcess{
Type: inventorypb.AgentType_RDS_EXPORTER,
TemplateLeftDelim: tdp.Left,
TemplateRightDelim: tdp.Right,
Args: args,
Env: env,
TextFiles: map[string]string{
"config": "---\n" + string(b),
},
RedactWords: words,
}, nil

To propagate AWS_CONTAINER_CREDENTIALS_RELATIVE_URI environment variable to rds exporter child process. Reduced as maximum as i can.
@BupycHuk BupycHuk removed the request for review from PavelKhripkov June 6, 2023 06:46
@petlitskiy petlitskiy closed this Jun 17, 2023
@petlitskiy petlitskiy deleted the feature/to_run_on_aws_fargate branch June 17, 2023 17:22
@artemgavrilov
Copy link
Contributor

Hi @petlitskiy , sorry for the delay. Are you still interested in this contribution? We would like to merge this change, can you please reopen this PR?

@artemgavrilov artemgavrilov self-requested a review June 28, 2023 12:58
@artemgavrilov artemgavrilov added the community Community contribution label Jun 28, 2023
@petlitskiy
Copy link
Author

petlitskiy commented Jun 28, 2023 via email

@artemgavrilov
Copy link
Contributor

@petlitskiy Please check that your email in git setting matches email specified in Github account, most likely this is the case.

@petlitskiy
Copy link
Author

petlitskiy commented Jun 30, 2023 via email

@petlitskiy
Copy link
Author

petlitskiy commented Jun 30, 2023 via email

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

Successfully merging this pull request may close these issues.

4 participants