CERT-Polska / karton

Distributed malware processing framework based on Python, Redis and S3.
https://karton-core.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
381 stars 45 forks source link

IAM auth: session token eventually expires #233

Closed yankovs closed 7 months ago

yankovs commented 10 months ago

Hey!

I noticed an issue in the IAM auth feature I made a PR for a while back. Real world kartons are supposed to be long-running services and shouldn't crash, so essentially KartonBackend should be initialized once in their startup process. This means that the s3 client will use the same session_token and eventually it will expire and cause the karton to fail processing tasks 100% of the time.

There are a couple of ways to deal with it I think are worth discussion:

yankovs commented 10 months ago

It seems like the second bullet might be the easiest, actually. Both InstanceMetadataProvider and ContainerProvider return a RefreshableCredentials object when calling load. So what we want should be already achievable as is. It is just that we throw away this object and statically use the creds it provides once

Instead, I believe this creds object should just be used to construct a session and then use self.s3 = session.client("s3") and then use the current codebase as is :). I'll experiment with this when I can.

nazywam commented 10 months ago

Second options sounds good! Do you maybe know if this happens only with AWS or are other possible backends are affected as well?

yankovs commented 10 months ago

Second options sounds good! Do you maybe know if this happens only with AWS or are other possible backends are affected as well?

Hey :)

I didn't test this with any other backend than ours, which is basically AWS ECS Fargate. I don't think I have the tools to test any other backend right now but if someone is willing to I'll be happy to help