-
Notifications
You must be signed in to change notification settings - Fork 154
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
Tamper protected Endpoint integration removal #2747
Changes from all commits
f4cf21e
392864f
cfcc30d
84b8b58
c1c9335
a02f6da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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: Tamper protected Endpoint integration removal | ||
|
||
# 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: | ||
|
||
# Affected component; a word indicating the component this changeset affects. | ||
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/elastic/elastic-agent/pull/2747 | ||
|
||
# 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/ingest-dev/issues/1882 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
package component | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"sort" | ||
"strings" | ||
|
@@ -76,6 +77,63 @@ type Unit struct { | |
Err error `yaml:"error,omitempty"` | ||
} | ||
|
||
// Signed Strongly typed configuration for the signed data | ||
type Signed struct { | ||
Data string `yaml:"data"` | ||
Signature string `yaml:"signature"` | ||
} | ||
|
||
// IsSigned Checks if the signature exists, safe to call on nil | ||
func (s *Signed) IsSigned() bool { | ||
return (s != nil && (len(s.Signature) > 0)) | ||
} | ||
|
||
// ErrNotFound is returned if the expected "signed" property itself or it's expected properties are missing or not a valid data type | ||
var ErrNotFound = errors.New("not found") | ||
|
||
// SignedFromPolicy Returns Signed instance from the nested map representation of the agent configuration | ||
func SignedFromPolicy(policy map[string]interface{}) (*Signed, error) { | ||
v, ok := policy["signed"] | ||
if !ok { | ||
return nil, fmt.Errorf("policy is not signed: %w", ErrNotFound) | ||
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. Should this maybe be a defined error? 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. from general use case point of view, it's the same meaning, we care if we have data or not, same for the tests. |
||
} | ||
|
||
signed, ok := v.(map[string]interface{}) | ||
if !ok { | ||
return nil, fmt.Errorf("policy \"signed\" is not map: %w", ErrNotFound) | ||
} | ||
|
||
data, err := getStringValue(signed, "data") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
signature, err := getStringValue(signed, "signature") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res := &Signed{ | ||
Data: data, | ||
Signature: signature, | ||
} | ||
return res, nil | ||
} | ||
|
||
func getStringValue(m map[string]interface{}, key string) (string, error) { | ||
v, ok := m[key] | ||
if !ok { | ||
return "", fmt.Errorf("missing signed \"%s\": %w", key, ErrNotFound) | ||
} | ||
|
||
s, ok := v.(string) | ||
if !ok { | ||
return "", fmt.Errorf("signed \"%s\" is not string: %w", key, ErrNotFound) | ||
} | ||
|
||
return s, nil | ||
} | ||
|
||
// Component is a set of units that needs to run. | ||
type Component struct { | ||
// ID is the unique ID of the component. | ||
|
@@ -111,6 +169,12 @@ func (c *Component) Type() string { | |
return "" | ||
} | ||
|
||
// Model components model | ||
type Model struct { | ||
Components []Component `yaml:"components,omitempty"` | ||
Signed *Signed `yaml:"signed,omitempty"` | ||
} | ||
|
||
// ToComponents returns the components that should be running based on the policy and | ||
// the current runtime specification. | ||
func (r *RuntimeSpecs) ToComponents( | ||
|
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.
Please add comments to each exposed struct and function. In proper format of
// {name} {description}
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.
added comments