Skip to content

Commit f1f7f75

Browse files
authored
Merge pull request #126 from RobsonSutton/add-role-attribute
[ISSUE-125] Add allow_restricted_indices setting to security role
2 parents c5d5a69 + db4cdbd commit f1f7f75

File tree

6 files changed

+23
-6
lines changed

6 files changed

+23
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ website/node_modules
2525
*.iml
2626
*.test
2727
*.iml
28+
*.vscode
2829

2930
website/vendor
3031

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
### Fixed
33
- Correctly identify a missing security user ([#101](https://github.com/elastic/terraform-provider-elasticstack/issues/101))
44
- Support **7.x** Elasticsearch < **7.15** by removing the default `media_type` attribute in the Append processor ([#118](https://github.com/elastic/terraform-provider-elasticstack/pull/118))
5+
- Add `allow_restricted_indices` setting to security role ([#125](https://github.com/elastic/terraform-provider-elasticstack/issues/125))
56

67
## [0.3.3] - 2023-03-22
78
### Fixed

docs/resources/elasticsearch_security_role.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ Optional:
9999

100100
- **field_security** (Block List, Max: 1) The document fields that the owners of the role have read access to. (see [below for nested schema](#nestedblock--indices--field_security))
101101
- **query** (String) A search query that defines the documents the owners of the role have read access to.
102+
- **allow_restricted_indices** (Boolean) Include matching restricted indices in names parameter (usage is strongly discouraged as it can grant unrestricted operations on critical data, make the entire system unstable or leak sensitive information).
102103

103104
<a id="nestedblock--indices--field_security"></a>
104105
### Nested Schema for `indices.field_security`

internal/elasticsearch/security/role.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ func ResourceRole() *schema.Resource {
126126
DiffSuppressFunc: utils.DiffJsonSuppress,
127127
Optional: true,
128128
},
129+
"allow_restricted_indices": {
130+
Description: "Include matching restricted indices in names parameter. Usage is strongly discouraged as it can grant unrestricted operations on critical data, make the entire system unstable or leak sensitive information.",
131+
Type: schema.TypeBool,
132+
Optional: true,
133+
},
129134
},
130135
},
131136
},
@@ -269,6 +274,10 @@ func resourceSecurityRolePut(ctx context.Context, d *schema.ResourceData, meta i
269274
}
270275
newIndex.FieldSecurity = &fieldSecurity
271276
}
277+
278+
allowRestrictedIndices := index["allow_restricted_indices"].(bool)
279+
newIndex.AllowRestrictedIndices = &allowRestrictedIndices
280+
272281
indices[i] = newIndex
273282
}
274283
role.Indices = indices
@@ -392,6 +401,7 @@ func flattenIndicesData(indices *[]models.IndexPerms) []interface{} {
392401
oi["names"] = index.Names
393402
oi["privileges"] = index.Privileges
394403
oi["query"] = index.Query
404+
oi["allow_restricted_indices"] = index.AllowRestrictedIndices
395405

396406
if index.FieldSecurity != nil {
397407
fsec := make(map[string]interface{})

internal/elasticsearch/security/role_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func TestAccResourceSecurityRole(t *testing.T) {
2424
Config: testAccResourceSecurityRoleCreate(roleName),
2525
Check: resource.ComposeTestCheckFunc(
2626
resource.TestCheckResourceAttr("elasticstack_elasticsearch_security_role.test", "name", roleName),
27+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_security_role.test", "indices.0.allow_restricted_indices", "true"),
2728
resource.TestCheckTypeSetElemAttr("elasticstack_elasticsearch_security_role.test", "indices.*.names.*", "index1"),
2829
resource.TestCheckTypeSetElemAttr("elasticstack_elasticsearch_security_role.test", "indices.*.names.*", "index2"),
2930
resource.TestCheckTypeSetElemAttr("elasticstack_elasticsearch_security_role.test", "cluster.*", "all"),
@@ -41,6 +42,7 @@ func TestAccResourceSecurityRole(t *testing.T) {
4142
resource.TestCheckNoResourceAttr("elasticstack_elasticsearch_security_role.test", "run_as"),
4243
resource.TestCheckNoResourceAttr("elasticstack_elasticsearch_security_role.test", "global"),
4344
resource.TestCheckNoResourceAttr("elasticstack_elasticsearch_security_role.test", "applications"),
45+
resource.TestCheckNoResourceAttr("elasticstack_elasticsearch_security_role.test", "indices.0.allow_restricted_indices"),
4446
),
4547
},
4648
},
@@ -58,8 +60,9 @@ resource "elasticstack_elasticsearch_security_role" "test" {
5860
cluster = ["all"]
5961
6062
indices {
61-
names = ["index1", "index2"]
62-
privileges = ["all"]
63+
names = ["index1", "index2"]
64+
privileges = ["all"]
65+
allow_restricted_indices = true
6366
}
6467
6568
applications {

internal/models/models.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ type Role struct {
2222
}
2323

2424
type IndexPerms struct {
25-
FieldSecurity *FieldSecurity `json:"field_security,omitempty"`
26-
Names []string `json:"names"`
27-
Privileges []string `json:"privileges"`
28-
Query *string `json:"query,omitempty"`
25+
FieldSecurity *FieldSecurity `json:"field_security,omitempty"`
26+
Names []string `json:"names"`
27+
Privileges []string `json:"privileges"`
28+
Query *string `json:"query,omitempty"`
29+
AllowRestrictedIndices *bool `json:"allow_restricted_indices,omitempty"`
2930
}
3031

3132
type FieldSecurity struct {

0 commit comments

Comments
 (0)