Hi everyone, I have an issue of S3 AccessDenied w...
# troubleshooting
a
Hi everyone, I have an issue of S3 AccessDenied when Flink restarts a job from latest checkpoint after EKS rolling-update. Basically, when we upgrade EKS cluster, it will gradually update nodes and pods residing on those nodes will be evicted. Therefore, Flink TMs or JM are impacted by the upgrade. However, after new TMs are instantiated, some of them fail to access S3 to get the latest checkpoint (we store checkpoint/savepoints in s3 bucket). I debugged the issue with AWS Support team, it looks like the request to s3 was made under the EKS node role, which is not able to access S3, instead of the role tied to the service account of Flink cluster. Example
Copy code
org.apache.flink.runtime.state.BackendBuildingException: Failed when trying to restore heap backend
	at org.apache.flink.runtime.state.heap.HeapKeyedStateBackendBuilder.restoreState(HeapKeyedStateBackendBuilder.java:172) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.runtime.state.heap.HeapKeyedStateBackendBuilder.build(HeapKeyedStateBackendBuilder.java:106) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.runtime.state.hashmap.HashMapStateBackend.createKeyedStateBackend(HashMapStateBackend.java:143) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.runtime.state.hashmap.HashMapStateBackend.createKeyedStateBackend(HashMapStateBackend.java:74) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.runtime.state.StateBackend.createKeyedStateBackend(StateBackend.java:149) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.streaming.api.operators.StreamTaskStateInitializerImpl.lambda$keyedStatedBackend$1(StreamTaskStateInitializerImpl.java:336) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.streaming.api.operators.BackendRestorerProcedure.attemptCreateAndRestore(BackendRestorerProcedure.java:168) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.streaming.api.operators.BackendRestorerProcedure.createAndRestore(BackendRestorerProcedure.java:135) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.streaming.api.operators.StreamTaskStateInitializerImpl.keyedStatedBackend(StreamTaskStateInitializerImpl.java:353) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.streaming.api.operators.StreamTaskStateInitializerImpl.streamOperatorStateContext(StreamTaskStateInitializerImpl.java:165) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.streaming.api.operators.AbstractStreamOperator.initializeState(AbstractStreamOperator.java:256) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.streaming.runtime.tasks.RegularOperatorChain.initializeStateAndOpenOperators(RegularOperatorChain.java:106) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.streaming.runtime.tasks.StreamTask.restoreGates(StreamTask.java:734) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.streaming.runtime.tasks.StreamTaskActionExecutor$1.call(StreamTaskActionExecutor.java:55) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.streaming.runtime.tasks.StreamTask.restoreInternal(StreamTask.java:709) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.streaming.runtime.tasks.StreamTask.restore(StreamTask.java:675) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.runtime.taskmanager.Task.runWithSystemExitMonitoring(Task.java:952) [flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.runtime.taskmanager.Task.restoreAndInvoke(Task.java:921) [flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.runtime.taskmanager.Task.doRun(Task.java:745) [flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.runtime.taskmanager.Task.run(Task.java:562) [flink-dist-1.17.1.jar:1.17.1]
	at java.lang.Thread.run(Thread.java:750) [?:1.8.0_392]
Caused by: com.facebook.presto.hive.s3.PrestoS3FileSystem$UnrecoverableS3OperationException: com.amazonaws.services.s3.model.AmazonS3Exception: Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: ABCDEFGHIJK; S3 Extended Request ID: abcdef123456; Proxy: null), S3 Extended Request ID: abcdef123456 (Path: s3://.../checkpoints/abcdef/chk-1234/ghijk)
	at com.facebook.presto.hive.s3.PrestoS3FileSystem$PrestoS3InputStream.lambda$openStream$2(PrestoS3FileSystem.java:1114) ~[?:?]
	at com.facebook.presto.hive.RetryDriver.run(RetryDriver.java:139) ~[?:?]
	at com.facebook.presto.hive.s3.PrestoS3FileSystem$PrestoS3InputStream.openStream(PrestoS3FileSystem.java:1099) ~[?:?]
	at com.facebook.presto.hive.s3.PrestoS3FileSystem$PrestoS3InputStream.openStream(PrestoS3FileSystem.java:1084) ~[?:?]
	at com.facebook.presto.hive.s3.PrestoS3FileSystem$PrestoS3InputStream.seekStream(PrestoS3FileSystem.java:1077) ~[?:?]
	at com.facebook.presto.hive.s3.PrestoS3FileSystem$PrestoS3InputStream.lambda$read$1(PrestoS3FileSystem.java:1021) ~[?:?]
	at com.facebook.presto.hive.RetryDriver.run(RetryDriver.java:139) ~[?:?]
	at com.facebook.presto.hive.s3.PrestoS3FileSystem$PrestoS3InputStream.read(PrestoS3FileSystem.java:1020) ~[?:?]
	at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) ~[?:1.8.0_392]
	at java.io.BufferedInputStream.read(BufferedInputStream.java:265) ~[?:1.8.0_392]
	at java.io.FilterInputStream.read(FilterInputStream.java:83) ~[?:1.8.0_392]
	at org.apache.flink.fs.s3presto.common.HadoopDataInputStream.read(HadoopDataInputStream.java:86) ~[?:?]
	at org.apache.flink.core.fs.FSDataInputStreamWrapper.read(FSDataInputStreamWrapper.java:50) ~[flink-dist-1.17.1.jar:1.17.1]
	at java.io.DataInputStream.readInt(DataInputStream.java:387) ~[?:1.8.0_392]
	at org.apache.flink.core.io.VersionedIOReadableWritable.read(VersionedIOReadableWritable.java:47) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.runtime.state.KeyedBackendSerializationProxy.read(KeyedBackendSerializationProxy.java:143) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.runtime.state.heap.HeapRestoreOperation.restore(HeapRestoreOperation.java:134) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.runtime.state.heap.HeapRestoreOperation.restore(HeapRestoreOperation.java:62) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.runtime.state.heap.HeapKeyedStateBackendBuilder.restoreState(HeapKeyedStateBackendBuilder.java:169) ~[flink-dist-1.17.1.jar:1.17.1]
	... 20 more
Caused by: com.amazonaws.services.s3.model.AmazonS3Exception: Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: ABCDEFGHIJK; S3 Extended Request ID: abcdef123456; Proxy: null)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1879) ~[?:?]
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleServiceErrorResponse(AmazonHttpClient.java:1418) ~[?:?]
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1387) ~[?:?]
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1157) ~[?:?]
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:814) ~[?:?]
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:781) ~[?:?]
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:755) ~[?:?]
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:715) ~[?:?]
	at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:697) ~[?:?]
	at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:561) ~[?:?]
	at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:541) ~[?:?]
	at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:5456) ~[?:?]
	at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:5403) ~[?:?]
	at com.amazonaws.services.s3.AmazonS3Client.getObject(AmazonS3Client.java:1524) ~[?:?]
	at com.facebook.presto.hive.s3.PrestoS3FileSystem$PrestoS3InputStream.lambda$openStream$2(PrestoS3FileSystem.java:1102) ~[?:?]
	at com.facebook.presto.hive.RetryDriver.run(RetryDriver.java:139) ~[?:?]
	at com.facebook.presto.hive.s3.PrestoS3FileSystem$PrestoS3InputStream.openStream(PrestoS3FileSystem.java:1099) ~[?:?]
	at com.facebook.presto.hive.s3.PrestoS3FileSystem$PrestoS3InputStream.openStream(PrestoS3FileSystem.java:1084) ~[?:?]
	at com.facebook.presto.hive.s3.PrestoS3FileSystem$PrestoS3InputStream.seekStream(PrestoS3FileSystem.java:1077) ~[?:?]
	at com.facebook.presto.hive.s3.PrestoS3FileSystem$PrestoS3InputStream.lambda$read$1(PrestoS3FileSystem.java:1021) ~[?:?]
	at com.facebook.presto.hive.RetryDriver.run(RetryDriver.java:139) ~[?:?]
	at com.facebook.presto.hive.s3.PrestoS3FileSystem$PrestoS3InputStream.read(PrestoS3FileSystem.java:1020) ~[?:?]
	at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) ~[?:1.8.0_392]
	at java.io.BufferedInputStream.read(BufferedInputStream.java:265) ~[?:1.8.0_392]
	at java.io.FilterInputStream.read(FilterInputStream.java:83) ~[?:1.8.0_392]
	at org.apache.flink.fs.s3presto.common.HadoopDataInputStream.read(HadoopDataInputStream.java:86) ~[?:?]
	at org.apache.flink.core.fs.FSDataInputStreamWrapper.read(FSDataInputStreamWrapper.java:50) ~[flink-dist-1.17.1.jar:1.17.1]
	at java.io.DataInputStream.readInt(DataInputStream.java:387) ~[?:1.8.0_392]
	at org.apache.flink.core.io.VersionedIOReadableWritable.read(VersionedIOReadableWritable.java:47) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.runtime.state.KeyedBackendSerializationProxy.read(KeyedBackendSerializationProxy.java:143) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.runtime.state.heap.HeapRestoreOperation.restore(HeapRestoreOperation.java:134) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.runtime.state.heap.HeapRestoreOperation.restore(HeapRestoreOperation.java:62) ~[flink-dist-1.17.1.jar:1.17.1]
	at org.apache.flink.runtime.state.heap.HeapKeyedStateBackendBuilder.restoreState(HeapKeyedStateBackendBuilder.java:169) ~[flink-dist-1.17.1.jar:1.17.1]
	... 20 more
The issue is similar to this - https://lists.apache.org/thread/00q2dplgyywnsxrv57lzrv01dzo65n5q. The only difference is that we use HashMapStateBackend for checkpointing, not RocksDB. I notice that this issue often happens with TMs handling keyed state process Thanks
j
Which credentials provider you use? Once IAM roles for service accounts (IRSA) are enabled, we should be able to use
com.amazonaws.auth.WebIdentityTokenCredentialsProvider
as the credentials provider and it is a typical way to set up IAM permission on spark/flink workload on EMR on EKS. For example, below is the hadoop configuration (core-site.xml) for the flink image of the EMR on EKS.
Copy code
<configuration>
  <property>
    <name>fs.s3a.aws.credentials.provider</name>
    <value>com.amazonaws.auth.WebIdentityTokenCredentialsProvider</value>
  </property>

  <property>
    <name>fs.s3.customAWSCredentialsProvider</name>
    <value>com.amazonaws.auth.WebIdentityTokenCredentialsProvider</value>
  </property>

  <property>
    <name>fs.s3.impl</name>
    <value>com.amazon.ws.emr.hadoop.fs.EmrFileSystem</value>
  </property>

  <property>
    <name>fs.s3n.impl</name>
    <value>com.amazon.ws.emr.hadoop.fs.EmrFileSystem</value>
  </property>

  <property>
    <name>fs.AbstractFileSystem.s3.impl</name>
    <value>org.apache.hadoop.fs.s3.EMRFSDelegate</value>
  </property>

  <property>
    <name>fs.s3.buffer.dir</name>
    <value>/mnt/s3,/mnt1/s3</value>
    <final>true</final>
  </property>
</configuration>
As you use Flink 1.17.1, you may consider using the latest EMR on EKS image - https://docs.aws.amazon.com/emr/latest/EMR-on-EKS-DevelopmentGuide/run-flink-jobs.html as EMR release 6.15.0 includes it.
d
@Anh Nguyen what is your flink configuration used for s3? Are you using iam role on worker nodes or s3 access?
a
Hi @Jaehyeon Kim and @Divye Mahajan, Thank you so much for your response, I dont set any flink configuration for s3 other than savepoint/checkpoint location. I also create a ServiceAccount yaml file with iam role. E.g.
Copy code
apiVersion: v1
kind: ServiceAccount
metadata:
  name: flink-acc
  namespace: flink-ns
  annotations:
    eks.amazonaws.com/role-arn: arn:aws:iam::123456789123:role/flink-acc
the S3 access policy is created in the iam role. My Flink cluster runs on AWS EKS so in the pod environment I see two environment variables
AWS_WEB_IDENTITY_TOKEN_FILE
and
AWS_ROLE_ARN
. I also set
s3.use-instance-credentials: "false"
It works fine when the Flink cluster is first deployed to EKS cluster. The issue only arises when some pod get evicted and new ones are launched by EKS (even it happens with some pods, not all). Because of not setting any credential providers, I assume by default Flink will use
DefaultAWSCredentialsProviderChain
which looks for Web Identity Token credentials from the environment or container (Reference: https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html) Did I miss anything?
r
We are facing this issue again in Production, does anybody know why the Flink TM pod is unable to assume the right IAM role and default to the EKS Cluster IAM's role who clearly donot have s3 policies to the S3 bucket. cc: @Anh Nguyen @Guruguha Marur Sreenivasa @saahil khurana
🙌 2
a
Hi @Gyula Fóra, @Martijn Visser Could you please help us with this issue? Thanks so much
👎 2
m
Please follow the Slack rules
a
Hi Martijn, Gyula, I forgot that we should not direct message people for troubleshooting, Jira assigning and PR review. I am so sorry about it. Could you please help me look into the issue if you have time. Thanks