s3-auth-checks.td 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. # Auth related for COPY TO expr.
  10. # COPY TO expressions should immediately succeed or fail on their first runs
  11. $ set-max-tries max-tries=1
  12. $ postgres-execute connection=postgres://mz_system:materialize@${testdrive.materialize-internal-sql-addr}
  13. ALTER SYSTEM SET enable_copy_to_expr = true;
  14. # There are 3 users with different permissions policies to validate:
  15. # User 'readwritedelete': PutObject, ListBucket, DeleteObject
  16. # User 'nodelete': PutObject, ListBucket
  17. # User 'read': GetObject, ListBucket
  18. ### Set up connections - one for each user
  19. > CREATE SECRET user_readwritedelete_secret AS '${arg.s3-user-readwritedelete-secret-key}'
  20. > CREATE SECRET user_nodelete_secret AS '${arg.s3-user-nodelete-secret-key}'
  21. > CREATE SECRET user_read_secret AS '${arg.s3-user-read-secret-key}'
  22. > CREATE CONNECTION user_readwritedelete_aws_conn
  23. TO AWS (
  24. ACCESS KEY ID = 'readwritedelete',
  25. SECRET ACCESS KEY = SECRET user_readwritedelete_secret,
  26. ENDPOINT = '${arg.aws-endpoint}',
  27. REGION = 'us-east-1'
  28. );
  29. > CREATE CONNECTION user_nodelete_aws_conn
  30. TO AWS (
  31. ACCESS KEY ID = 'nodelete',
  32. SECRET ACCESS KEY = SECRET user_nodelete_secret,
  33. ENDPOINT = '${arg.aws-endpoint}',
  34. REGION = 'us-east-1'
  35. );
  36. > CREATE CONNECTION user_read_aws_conn
  37. TO AWS (
  38. ACCESS KEY ID = 'read',
  39. SECRET ACCESS KEY = SECRET user_read_secret,
  40. ENDPOINT = '${arg.aws-endpoint}',
  41. REGION = 'us-east-1'
  42. );
  43. ### End setup
  44. # read user should fail immediately
  45. ! COPY (SELECT generate_series(1, 100)) TO 's3://copytos3/auth_test'
  46. WITH (
  47. AWS CONNECTION = user_read_aws_conn,
  48. FORMAT = 'csv'
  49. );
  50. contains:AccessDenied
  51. # nodelete user should fail immediately
  52. ! COPY (SELECT generate_series(1, 100)) TO 's3://copytos3/auth_test'
  53. WITH (
  54. AWS CONNECTION = user_nodelete_aws_conn,
  55. FORMAT = 'csv'
  56. );
  57. contains:AccessDenied
  58. # user with readwritedelete permissions should succeed copying into the same
  59. # path which indicates that the previous permissions failures did not
  60. # write anything to the S3 path at all and corrupt it
  61. > COPY (SELECT generate_series(1, 100)) TO 's3://copytos3/auth_test'
  62. WITH (
  63. AWS CONNECTION = user_readwritedelete_aws_conn,
  64. FORMAT = 'csv'
  65. );
  66. # Test broken AWS connection error message at copy time
  67. > CREATE CONNECTION broken_aws_conn
  68. TO AWS (
  69. ASSUME ROLE ARN = 'arn:aws:iam::400121260767:role/MZS3Exporter',
  70. ENDPOINT = '${arg.aws-endpoint}',
  71. REGION = 'us-east-1'
  72. );
  73. ! COPY (SELECT generate_series(1, 100)) TO 's3://copytos3/auth_test'
  74. WITH (
  75. AWS CONNECTION = broken_aws_conn,
  76. FORMAT = 'csv'
  77. );
  78. contains: dispatch failure: other: an error occurred while loading credentials