Skip to content

Commit

Permalink
Merge pull request #20108 from hashicorp/b-lakeformation-iam-allowed
Browse files Browse the repository at this point in the history
lakeformation: Fix various bugs including SELECT permission issues
  • Loading branch information
YakDriver authored Jul 8, 2021
2 parents d116587 + 8b7cb8e commit f268ddf
Show file tree
Hide file tree
Showing 13 changed files with 1,400 additions and 547 deletions.
7 changes: 7 additions & 0 deletions .changelog/20108.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:bug
resource/aws_lakeformation_permissions: Fix various problems with permissions including select-only
```

```release-note:bug
data-source/aws_lakeformation_permissions: Fix various problems with permissions including select-only
```
11 changes: 7 additions & 4 deletions aws/data_source_aws_lakeformation_data_lake_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
)

func testAccAWSLakeFormationDataLakeSettingsDataSource_basic(t *testing.T) {
callerIdentityName := "data.aws_caller_identity.current"
resourceName := "data.aws_lakeformation_data_lake_settings.test"

resource.Test(t, resource.TestCase{
Expand All @@ -20,9 +19,9 @@ func testAccAWSLakeFormationDataLakeSettingsDataSource_basic(t *testing.T) {
{
Config: testAccAWSLakeFormationDataLakeSettingsDataSourceConfig_basic,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(resourceName, "catalog_id", callerIdentityName, "account_id"),
resource.TestCheckResourceAttrPair(resourceName, "catalog_id", "data.aws_caller_identity.current", "account_id"),
resource.TestCheckResourceAttr(resourceName, "admins.#", "1"),
resource.TestCheckResourceAttrPair(resourceName, "admins.0", callerIdentityName, "arn"),
resource.TestCheckResourceAttrPair(resourceName, "admins.0", "data.aws_iam_session_context.current", "issuer_arn"),
),
},
},
Expand All @@ -32,9 +31,13 @@ func testAccAWSLakeFormationDataLakeSettingsDataSource_basic(t *testing.T) {
const testAccAWSLakeFormationDataLakeSettingsDataSourceConfig_basic = `
data "aws_caller_identity" "current" {}
data "aws_iam_session_context" "current" {
arn = data.aws_caller_identity.current.arn
}
resource "aws_lakeformation_data_lake_settings" "test" {
catalog_id = data.aws_caller_identity.current.account_id
admins = [data.aws_caller_identity.current.arn]
admins = [data.aws_iam_session_context.current.issuer_arn]
}
data "aws_lakeformation_data_lake_settings" "test" {
Expand Down
12 changes: 12 additions & 0 deletions aws/data_source_aws_lakeformation_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,18 @@ func dataSourceAwsLakeFormationPermissionsRead(d *schema.ResourceData, meta inte
if v, ok := d.GetOk("table"); ok && len(v.([]interface{})) > 0 {
// since perm list could include TableWithColumns, get the right one
for _, perm := range cleanPermissions {
if perm.Resource == nil {
continue
}

if perm.Resource.TableWithColumns != nil && perm.Resource.TableWithColumns.ColumnWildcard != nil {
if err := d.Set("table", []interface{}{flattenLakeFormationTableWithColumnsResourceAsTable(perm.Resource.TableWithColumns)}); err != nil {
return fmt.Errorf("error setting table: %w", err)
}
tableSet = true
break
}

if perm.Resource.Table != nil {
if err := d.Set("table", []interface{}{flattenLakeFormationTableResource(perm.Resource.Table)}); err != nil {
return fmt.Errorf("error setting table: %w", err)
Expand Down
168 changes: 82 additions & 86 deletions aws/data_source_aws_lakeformation_permissions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,28 +148,28 @@ data "aws_partition" "current" {}
resource "aws_iam_role" "test" {
name = %[1]q
path = "/"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lakeformation.${data.aws_partition.current.dns_suffix}"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
assume_role_policy = jsonencode({
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "glue.${data.aws_partition.current.dns_suffix}"
}
}]
Version = "2012-10-17"
})
}
data "aws_caller_identity" "current" {}
data "aws_iam_session_context" "current" {
arn = data.aws_caller_identity.current.arn
}
resource "aws_lakeformation_data_lake_settings" "test" {
admins = [data.aws_caller_identity.current.arn]
admins = [data.aws_iam_session_context.current.issuer_arn]
}
resource "aws_lakeformation_permissions" "test" {
Expand All @@ -196,21 +196,16 @@ resource "aws_iam_role" "test" {
name = %[1]q
path = "/"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "glue.${data.aws_partition.current.dns_suffix}"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
assume_role_policy = jsonencode({
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "glue.${data.aws_partition.current.dns_suffix}"
}
}]
Version = "2012-10-17"
})
}
resource "aws_s3_bucket" "test" {
Expand All @@ -225,8 +220,12 @@ resource "aws_lakeformation_resource" "test" {
data "aws_caller_identity" "current" {}
data "aws_iam_session_context" "current" {
arn = data.aws_caller_identity.current.arn
}
resource "aws_lakeformation_data_lake_settings" "test" {
admins = [data.aws_caller_identity.current.arn]
admins = [data.aws_iam_session_context.current.issuer_arn]
}
resource "aws_lakeformation_permissions" "test" {
Expand Down Expand Up @@ -259,25 +258,18 @@ resource "aws_iam_role" "test" {
name = %[1]q
path = "/"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "glue.${data.aws_partition.current.dns_suffix}"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
assume_role_policy = jsonencode({
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "glue.${data.aws_partition.current.dns_suffix}"
}
}]
Version = "2012-10-17"
})
}
data "aws_caller_identity" "current" {}
resource "aws_s3_bucket" "test" {
bucket = %[1]q
}
Expand All @@ -286,8 +278,14 @@ resource "aws_glue_catalog_database" "test" {
name = %[1]q
}
data "aws_caller_identity" "current" {}
data "aws_iam_session_context" "current" {
arn = data.aws_caller_identity.current.arn
}
resource "aws_lakeformation_data_lake_settings" "test" {
admins = [data.aws_caller_identity.current.arn]
admins = [data.aws_iam_session_context.current.issuer_arn]
}
resource "aws_lakeformation_permissions" "test" {
Expand Down Expand Up @@ -321,25 +319,18 @@ resource "aws_iam_role" "test" {
name = %[1]q
path = "/"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "glue.${data.aws_partition.current.dns_suffix}"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
assume_role_policy = jsonencode({
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "glue.${data.aws_partition.current.dns_suffix}"
}
}]
Version = "2012-10-17"
})
}
data "aws_caller_identity" "current" {}
resource "aws_s3_bucket" "test" {
bucket = %[1]q
}
Expand All @@ -353,8 +344,14 @@ resource "aws_glue_catalog_table" "test" {
database_name = aws_glue_catalog_database.test.name
}
data "aws_caller_identity" "current" {}
data "aws_iam_session_context" "current" {
arn = data.aws_caller_identity.current.arn
}
resource "aws_lakeformation_data_lake_settings" "test" {
admins = [data.aws_caller_identity.current.arn]
admins = [data.aws_iam_session_context.current.issuer_arn]
}
resource "aws_lakeformation_permissions" "test" {
Expand Down Expand Up @@ -389,25 +386,18 @@ resource "aws_iam_role" "test" {
name = %[1]q
path = "/"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "glue.${data.aws_partition.current.dns_suffix}"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
assume_role_policy = jsonencode({
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "glue.${data.aws_partition.current.dns_suffix}"
}
}]
Version = "2012-10-17"
})
}
data "aws_caller_identity" "current" {}
resource "aws_glue_catalog_database" "test" {
name = %[1]q
}
Expand All @@ -432,8 +422,14 @@ resource "aws_glue_catalog_table" "test" {
}
}
data "aws_caller_identity" "current" {}
data "aws_iam_session_context" "current" {
arn = data.aws_caller_identity.current.arn
}
resource "aws_lakeformation_data_lake_settings" "test" {
admins = [data.aws_caller_identity.current.arn]
admins = [data.aws_iam_session_context.current.issuer_arn]
}
resource "aws_lakeformation_permissions" "test" {
Expand Down
8 changes: 8 additions & 0 deletions aws/internal/service/lakeformation/enum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package lakeformation

const (
TableNameAllTables = "ALL_TABLES"
TableTypeTable = "Table"
TableTypeTableWithColumns = "TableWithColumns"
IAMAllowedPrincipals = "IAM_ALLOWED_PRINCIPALS"
)
Loading

0 comments on commit f268ddf

Please sign in to comment.