-
Notifications
You must be signed in to change notification settings - Fork 148
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
Add support for pre existing Active Directory user #5988
Merged
Merged
Changes from 7 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
5c5763a
unpriviledged ad works'
michalpristas b6b1e9d
Merge branch 'main' of github.com:elastic/elastic-agent into feat/unp…
michalpristas 4041e3e
Ensure rights for AD users
michalpristas d4d253f
Merge branch 'main' of github.com:elastic/elastic-agent into feat/unp…
michalpristas 43feb5e
changelog
michalpristas d115977
Merge branch 'main' of github.com:elastic/elastic-agent into feat/unp…
michalpristas ab9debd
support for mac and unix
michalpristas 6a2613f
Update internal/pkg/agent/cmd/install.go
michalpristas 233497f
Update internal/pkg/agent/cmd/unprivileged.go
michalpristas fa3fa8f
Merge branch 'main' into feat/unprivileged/ad
michalpristas a549377
added e2e tests for darwin and linux
michalpristas ffdf4a4
reverted sample_test
michalpristas fb78394
mage fmt
michalpristas a283ea2
Merge branch 'main' into feat/unprivileged/ad
michalpristas 2bc5531
Merge branch 'main' of github.com:elastic/elastic-agent into feat/unp…
michalpristas 3e9a9ab
Merge branch 'feat/unprivileged/ad' of github.com:michalpristas/elast…
michalpristas dec27ef
do not require password
michalpristas 7f0ae82
more strict regex
michalpristas d9b137b
fix description in changelog
michalpristas 111b576
Merge branch 'main' into feat/unprivileged/ad
michalpristas 8c550c4
Merge branch 'main' of github.com:elastic/elastic-agent into feat/unp…
michalpristas e831bd2
resolved review comments
michalpristas 658d5d9
Merge branch 'feat/unprivileged/ad' of github.com:michalpristas/elast…
michalpristas 13ce0d6
linter
michalpristas 674e92a
handle g115 in user_windows.go
michalpristas e1590cc
Merge branch 'main' into feat/unprivileged/ad
michalpristas d5d3122
Merge branch 'main' of github.com:elastic/elastic-agent into feat/unp…
michalpristas ae74bc4
more test coverage
michalpristas edc32f7
Merge branch 'feat/unprivileged/ad' of github.com:michalpristas/elast…
michalpristas 998eca7
fix broken windows UT
michalpristas 626a8a3
coverage
michalpristas ac9ac30
fixed logic for UnprivilegedUser
michalpristas 902686a
fixed windows tests
michalpristas 48a3fd7
Merge branch 'main' into feat/unprivileged/ad
michalpristas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...ents/1731314919-Added-support-for-custom-Active-Directory-user-for-unprivileged-mode.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Kind can be one of: | ||
# - breaking-change: a change to previously-documented behavior | ||
# - deprecation: functionality that is being removed in a later release | ||
# - bug-fix: fixes a problem in a previous version | ||
# - enhancement: extends functionality but does not break or fix existing behavior | ||
# - feature: new functionality | ||
# - known-issue: problems that we are aware of in a given version | ||
# - security: impacts on the security of a product or a user’s deployment. | ||
# - upgrade: important information for someone upgrading from a prior version | ||
# - other: does not fit into any of the other categories | ||
kind: feature | ||
|
||
# Change summary; a 80ish characters long description of the change. | ||
summary: Added support for pre-existing Active Directory user for unprivileged mode | ||
|
||
# Long description; in case the summary is not enough to describe the change | ||
# this field accommodate a description without length limits. | ||
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment. | ||
description: User can specify custom pre-existing user for running unprivileged mode. This user will be gived permissions to log on as a service. | ||
|
||
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc. | ||
component: | ||
|
||
# PR URL; optional; the PR number that added the changeset. | ||
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added. | ||
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number. | ||
# Please provide it if you are adding a fragment for a different PR. | ||
#pr: https://github.com/owner/repo/1234 | ||
|
||
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of). | ||
# If not present is automatically filled by the tooling with the issue linked to the PR number. | ||
issue: https://github.com/elastic/elastic-agent/issues/4585 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ const ( | |
) | ||
|
||
// Install installs Elastic Agent persistently on the system including creating and starting its service. | ||
func Install(cfgFile, topPath string, unprivileged bool, log *logp.Logger, pt *progressbar.ProgressBar, streams *cli.IOStreams) (utils.FileOwner, error) { | ||
func Install(cfgFile, topPath string, unprivileged bool, log *logp.Logger, pt *progressbar.ProgressBar, streams *cli.IOStreams, customUser, customGroup, userPassword string) (utils.FileOwner, error) { | ||
dir, err := findDirectory() | ||
if err != nil { | ||
return utils.FileOwner{}, errors.New(err, "failed to discover the source directory for installation", errors.TypeFilesystem) | ||
|
@@ -49,13 +49,15 @@ func Install(cfgFile, topPath string, unprivileged bool, log *logp.Logger, pt *p | |
var ownership utils.FileOwner | ||
username := "" | ||
groupName := "" | ||
password := "" | ||
if unprivileged { | ||
username = ElasticUsername | ||
groupName = ElasticGroupName | ||
ownership, err = EnsureUserAndGroup(username, groupName, pt) | ||
username, password = UnprivilegedUser(customUser, userPassword) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why only allow custom user for unprivileged mode? Do we not allow to specify custom user when installing in privileged mode? |
||
groupName = UnprivilegedGroup(customGroup) | ||
ownership, err = EnsureUserAndGroup(username, groupName, pt, username == ElasticUsername && password == "") // force create only elastic user | ||
if err != nil { | ||
// error context already added by EnsureUserAndGroup | ||
return utils.FileOwner{}, err | ||
|
||
} | ||
} | ||
|
||
|
@@ -147,7 +149,7 @@ func Install(cfgFile, topPath string, unprivileged bool, log *logp.Logger, pt *p | |
|
||
// install service | ||
pt.Describe("Installing service") | ||
err = InstallService(topPath, ownership, username, groupName) | ||
err = InstallService(topPath, ownership, username, groupName, password) | ||
if err != nil { | ||
pt.Describe("Failed to install service") | ||
// error context already added by InstallService | ||
|
@@ -371,11 +373,12 @@ func StatusService(topPath string) (service.Status, error) { | |
} | ||
|
||
// InstallService installs the service. | ||
func InstallService(topPath string, ownership utils.FileOwner, username string, groupName string) error { | ||
opts, err := withServiceOptions(username, groupName) | ||
func InstallService(topPath string, ownership utils.FileOwner, username string, groupName string, password string) error { | ||
opts, err := withServiceOptions(username, groupName, password) | ||
if err != nil { | ||
return fmt.Errorf("error getting service installation options: %w", err) | ||
} | ||
|
||
svc, err := newService(topPath, opts...) | ||
if err != nil { | ||
return fmt.Errorf("error creating new service handler for install: %w", err) | ||
|
@@ -482,3 +485,24 @@ func CreateInstallMarker(topPath string, ownership utils.FileOwner) error { | |
_ = handle.Close() | ||
return fixInstallMarkerPermissions(markerFilePath, ownership) | ||
} | ||
|
||
func UnprivilegedUser(username, password string) (string, string) { | ||
if username != "" && password != "" { | ||
return username, password | ||
} | ||
|
||
if username != "" && runtime.GOOS != "windows" { | ||
// password only required for windows | ||
return username, password | ||
} | ||
|
||
return ElasticUsername, "" | ||
} | ||
|
||
func UnprivilegedGroup(groupName string) string { | ||
if groupName != "" { | ||
return groupName | ||
} | ||
|
||
return ElasticGroupName | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,3 +177,5 @@ func dsclExec(args ...string) error { | |
} | ||
return nil | ||
} | ||
|
||
func EnsureRights(_ string) error { return nil } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.