Skip to content

feat(otelcol): add support for htpasswd file authentication #3916

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

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

Conversation

pkarakal
Copy link

PR Description

This adds support for using htpasswd for server authentication. Since otelcol.auth.basic is a wrapper around basicauthextension, which already supports both inline and file based server authentication, this adds such support for alloy as well. This would be really useful when we want to have multiple users trying to send data to Alloy and we don't want to a reverse proxy for authenticating calls.

This also makes the username and password fields optional since we should be able to just use htpasswd files for server side authentication. They must be filled in when the handler is used for client authentication.

PR Checklist

  • CHANGELOG.md updated
  • Documentation added
  • Tests updated

@CLAassistant
Copy link

CLAassistant commented Jun 29, 2025

CLA assistant check
All committers have signed the CLA.

@pkarakal pkarakal force-pushed the basic-auth-htpasswd branch from 920e168 to f15ea16 Compare June 29, 2025 13:29
@pkarakal pkarakal marked this pull request as ready for review June 29, 2025 13:30
@pkarakal pkarakal requested review from clayton-cornell and a team as code owners June 29, 2025 13:30
@pkarakal pkarakal force-pushed the basic-auth-htpasswd branch from f15ea16 to c9b7cb7 Compare June 29, 2025 15:25
Comment on lines 34 to 35

htpasswd_file = "/etc/alloy/.htpasswd"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
htpasswd_file = "/etc/alloy/.htpasswd"

The usage section only lists required attributes and blocks. You could add an example to the example section though.

},
}, nil
c := &basicauthextension.Config{
Htpasswd: &basicauthextension.HtpasswdSettings{},
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be better if this is only created if args.HtpasswdFile is not empty.

Username string `alloy:"username,attr,optional"`
Password alloytypes.Secret `alloy:"password,attr,optional"`

HtpasswdFile string `alloy:"htpasswd_file,attr,optional"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
HtpasswdFile string `alloy:"htpasswd_file,attr,optional"`
HtpasswdFile string `alloy:"htpasswd_file,block,optional"`

To match OTel, you'll need to create an htpasswd block which has two attributes - file and inline.

Copy link
Author

Choose a reason for hiding this comment

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

so in case the htpasswd block is provided do you want to ignore the username password that may be provided? Asking mainly cause the extension supports having both file and inline, and inline is currently created by just combining username/password, which is a behavior I tried to keep.

Copy link
Author

Choose a reason for hiding this comment

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

@ptodev feel free to let me know if that's what you had in mind.

Comment on lines 89 to 107
if args.HtpasswdFile != "" {
c.Htpasswd.File = args.HtpasswdFile
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The best way to do the conversion is to make htpasswd a struct and make a convert function for it, similarly to KafkaExporterSignalConfig.

@ptodev ptodev self-assigned this Jul 3, 2025
@pkarakal pkarakal force-pushed the basic-auth-htpasswd branch from c9b7cb7 to b780c89 Compare July 8, 2025 17:31
@pkarakal pkarakal force-pushed the basic-auth-htpasswd branch from b780c89 to fa9cb16 Compare July 8, 2025 17:44
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.

3 participants