-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[filebeat] Elasticsearch state storage for httpjson and cel inputs (#…
…41446) This enables Elasticsearch as State Store Backend for Security Integrations for the Agentless solution. The scope of this change was narrowed down to supporting only `httpjson` inputs in order to support Okta integration for the initial release. All the other integrations inputs still use the file storage as before. This is a short term solution for the state storage for k8s. The feature currently can only be enabled with the `AGENTLESS_ELASTICSEARCH_STATE_STORE_INPUT_TYPES` env var. The existing code relied on the inputs state storage to be fully configurable before the main beat managers runs. The change delays the configuration of `httpjson` input to the time when the actual configuration is received from the Agent. Example of the state storage index content for Okta integration: ``` { "took": 6, "timed_out": false, "_shards": { "total": 1, "successful": 1, "skipped": 0, "failed": 0 }, "hits": { "total": { "value": 1, "relation": "eq" }, "max_score": 1, "hits": [ { "_index": "agentless-state-httpjson-okta.system-028ecf4b-babe-44c6-939e-9e3096af6959", "_id": "httpjson::httpjson-okta.system-028ecf4b-babe-44c6-939e-9e3096af6959::https://dev-36006609.okta.com/api/v1/logs", "_seq_no": 39, "_primary_term": 1, "_score": 1, "_source": { "v": { "ttl": 1800000000000, "updated": "2024-10-24T20:21:22.032Z", "cursor": { "published": "2024-10-24T20:19:53.542Z" } } } } ] } } ``` The naming convention for all state store is `agentless-state-<input id>`, since the expectation for agentless we would have only one agent per policy and the agents are ephemeral. Closes https://github.com/elastic/security-team/issues/11101 Co-authored-by: Orestis Floros <orestis.floros@elastic.co>
- Loading branch information
Showing
29 changed files
with
1,313 additions
and
124 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package features | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
) | ||
|
||
// List of input types Elasticsearch state store is enabled for | ||
var esTypesEnabled map[string]struct{} | ||
|
||
var isESEnabled bool | ||
|
||
func init() { | ||
initFromEnv("AGENTLESS_ELASTICSEARCH_STATE_STORE_INPUT_TYPES") | ||
} | ||
|
||
func initFromEnv(envName string) { | ||
esTypesEnabled = make(map[string]struct{}) | ||
|
||
arr := strings.Split(os.Getenv(envName), ",") | ||
for _, e := range arr { | ||
k := strings.TrimSpace(e) | ||
if k != "" { | ||
esTypesEnabled[k] = struct{}{} | ||
} | ||
} | ||
isESEnabled = len(esTypesEnabled) > 0 | ||
} | ||
|
||
// IsElasticsearchStateStoreEnabled returns true if feature is enabled for agentless | ||
func IsElasticsearchStateStoreEnabled() bool { | ||
return isESEnabled | ||
} | ||
|
||
// IsElasticsearchStateStoreEnabledForInput returns true if the provided input type uses Elasticsearch for state storage if the Elasticsearch state store feature is enabled | ||
func IsElasticsearchStateStoreEnabledForInput(inputType string) bool { | ||
if IsElasticsearchStateStoreEnabled() { | ||
_, ok := esTypesEnabled[inputType] | ||
return ok | ||
} | ||
return false | ||
} |
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,86 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package features | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_initFromEnv(t *testing.T) { | ||
const envName = "TEST_AGENTLESS_ENV" | ||
|
||
t.Run("Without setting env", func(t *testing.T) { | ||
// default init | ||
assert.False(t, IsElasticsearchStateStoreEnabled()) | ||
assert.Empty(t, esTypesEnabled) | ||
assert.False(t, IsElasticsearchStateStoreEnabledForInput("xxx")) | ||
|
||
// init from env | ||
initFromEnv(envName) | ||
assert.False(t, IsElasticsearchStateStoreEnabled()) | ||
assert.Empty(t, esTypesEnabled) | ||
assert.False(t, IsElasticsearchStateStoreEnabledForInput("xxx")) | ||
}) | ||
|
||
tests := []struct { | ||
name string | ||
value string | ||
wantEnabled bool | ||
wantContains []string | ||
}{ | ||
{ | ||
name: "Empty", | ||
value: "", | ||
wantEnabled: false, | ||
wantContains: nil, | ||
}, | ||
{ | ||
name: "Single value", | ||
value: "xxx", | ||
wantEnabled: true, | ||
wantContains: []string{"xxx"}, | ||
}, | ||
{ | ||
name: "Multiple values", | ||
value: "xxx,yyy", | ||
wantEnabled: true, | ||
wantContains: []string{"xxx", "yyy"}, | ||
}, | ||
{ | ||
name: "Multiple values with spaces", | ||
value: ",,, , xxx , yyy, ,,,,", | ||
wantEnabled: true, | ||
wantContains: []string{"xxx", "yyy"}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Setenv(envName, tt.value) | ||
initFromEnv(envName) | ||
|
||
assert.Equal(t, tt.wantEnabled, IsElasticsearchStateStoreEnabled()) | ||
for _, contain := range tt.wantContains { | ||
assert.Contains(t, esTypesEnabled, contain) | ||
assert.True(t, IsElasticsearchStateStoreEnabledForInput(contain)) | ||
} | ||
assert.Len(t, esTypesEnabled, len(tt.wantContains)) | ||
}) | ||
} | ||
} |
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
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
Oops, something went wrong.