babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
steveb8n 2021-01-11T01:05:44.070100Z

Q: I’m planning to convert my CI aws bb scripts from using shell calls to use the new aws pod. I’d like to start using Vault at the same time https://github.com/99designs/aws-vault

borkdude 2021-01-11T08:48:48.071500Z

@steveb8n I'm not sure about the details of this by @jeroenvandijk could probably tell you more

borkdude 2021-01-11T08:49:16.071700Z

What is always possible is to use the credential_process provider to shell out to some custom script which connects to custom providers

steveb8n 2021-01-11T08:52:49.071900Z

thanks. good to know that there’s a programmatic way to do this. since Vault is considered a creds best practice, eventually the bb pod will support it

steveb8n 2021-01-11T08:53:04.072100Z

hopefully it just works 🙏

borkdude 2021-01-11T08:53:54.072300Z

Maybe also good to post an issue

steveb8n 2021-01-11T09:02:36.072500Z

I’ll give it a try and will log an issue if it doesn’t work. otherwise I’ll provide some doc for you if it needs some extra config

2021-01-11T09:04:50.072700Z

@steveb8n I haven’t used aws-vault and I’m not familair with it’s features. But I assume it can be made compatible with credential_process . Can the tool print temporary credentials to stdout?

steveb8n 2021-01-11T09:05:15.073Z

no idea. it’ll be the first time I’m using it as well

steveb8n 2021-01-11T09:05:34.073200Z

but I was advised by AWS architects that I should be using it

steveb8n 2021-01-11T09:05:52.073500Z

so I’ll report back. thanks for replying 🙂

2021-01-11T09:05:53.073700Z

Ok 🙂 They say a lot of things 😅

borkdude 2021-01-11T09:06:00.074Z

you can always make it print the creds in JSON using a custom script

steveb8n 2021-01-11T09:06:30.074200Z

dat klopt 😉

steveb8n 2021-01-11T09:08:03.074500Z

that said, since I’m providing enterprise SAAS I need to be able to show best practice security so I’ll follow advice like this

2021-01-11T09:08:39.074700Z

I’m joking, the aws-fault is probably a good practise. Just not the only one. @lukaszkorecki is using AWS SSO. I think that could be an even better practise

steveb8n 2021-01-11T09:08:58.074900Z

yeah, I’m also using a yubikey

2021-01-11T09:09:00.075100Z

I’m using Okta (similar to AWS SSO)

steveb8n 2021-01-11T09:09:20.075300Z

but still need to configure assumed roles. so many layers!

2021-01-11T09:09:34.075500Z

yeah ignorance is bliss

💯 1
steveb8n 2021-01-11T09:09:41.075700Z

Okta was founded by my former manager. I know it well

steveb8n 2021-01-11T09:10:39.076Z

</end> name dropping

2021-01-11T09:10:45.076200Z

Cool! I started using it before there was AWS SSO and haven’t tried that yet. So I can not make a proper comparision. I’m assuming AWS SSO is a lot easier to use with AWS. Had to build my own tool for Okta

steveb8n 2021-01-11T09:12:06.076400Z

I’m using Cognito for my users. It’s not as nice as Auth0 etc but it removes an external dependency. I’d bet AWS SSO is similar. Okta is bound to be better since it’s their specialty

steveb8n 2021-01-11T09:13:54.076900Z

Thanks for the feedback. I’ll report back

👍 1
lukasz 2021-01-11T14:48:22.081400Z

I think you can now wire things up a bit differently with Okta and AWS SSO - meaning, that Okta is just a SAML 2.0 idP (we use Google G-Suite/Workspace/Apps), and from there it doesn't really matter how you log in after running aws sso login --profile=.... - my team just has to copy the aws config from our repo, with all of the required profile entries (account IDs, assumed roles etc) and works out of the box. I have never used aws-vault and Okta's own AWS auth (I believe it's a thing) so cannot comment on that

nate 2021-01-11T17:23:05.084300Z

looks like aws-vault exposes creds as environment variables, so the babashka pod should just work?

lukasz 2021-01-11T17:24:00.084500Z

Yes

lukasz 2021-01-11T17:25:07.084700Z

there's a similar tool for AWS SSO https://github.com/linaro-its/aws2-wrap (I rewrote it in Clojure as a custom auth provider for aws-api)

lukasz 2021-01-12T15:52:33.102200Z

Thanks!

borkdude 2021-01-12T16:00:13.102400Z

@jeroenvandijk Maybe a stupid question, but is there a reason not to call the AWS SSO in the main bb script and then pass the credentials via the basic credential provider?

2021-01-12T16:01:15.102700Z

That would be possible but you would have to copy paste this code everywhere or put it in a library

2021-01-12T16:01:39.102900Z

Also if you want to use it with other tools it’s handy to have it as a credential_process. E.g. for when you do want to use the aws cli tool

borkdude 2021-01-12T16:02:35.103300Z

Sure!

borkdude 2021-01-12T16:02:59.103500Z

Wouldn't you have to copy/paste (or librarify) this code anyway, regardless on which side you use it?

2021-01-12T16:07:25.104300Z

My idea is to have a parameterized script that I can use for multiple AWS profiles in ~/.aws/credentials e.g.

[production]
credential_process = bb tools/aws_fetch_sso.clj --region us-east-1 --account-id 1111111 --role-name Admin --startUrl <https://your-start-url-hostname.awsapps.com/start>

[staging]
credential_process = bb tools/aws_fetch_sso.clj --region us-east-1 --account-id 2222222 --role-name SomeOtherRole --startUrl <https://your-start-url-hostname.awsapps.com/start>

borkdude 2021-01-12T16:07:57.104600Z

nice

2021-01-12T16:08:23.104800Z

Compared to the aws cli solution this is much less cumbersome. With aws cli, you have to run aws config and I had know idea how it worked until I found a blog post that was describing all the steps. No dependency on Python here 🙂

2021-01-12T16:10:17.105400Z

btw, I noticed that the babashka aws pod is quite an improvement on the aws cli in startup time

🎉 1
2021-01-13T14:51:43.116200Z

@lukaszkorecki I added caching to the aws sso credential_process script. So ready for usage I think 🙂 It also works with the aws cli https://gist.github.com/jeroenvandijk/ace7432be94d083e63729ac313a0b78f

lukasz 2021-01-13T15:24:42.116500Z

@jeroenvandijk really cool - if I understand correctly, most SDKs can pick up the credential_process option, including bb's aws pod?

2021-01-13T16:15:35.116700Z

@lukaszkorecki yes, from experience I know this to be true for the aws cli (so maybe also python skd’s) and the java sdk (used by Amazonica). aws-api doesn’t support it yet (https://github.com/cognitect-labs/aws-api/issues/73)

lukasz 2021-01-13T16:17:45.117300Z

Awesome, that's super helpful

👍 1
borkdude 2021-01-13T16:30:17.117600Z

@jeroenvandijk when you're done developing this, maybe we could add it to the docs of the pod

borkdude 2021-01-13T16:30:32.117800Z

or to an examples dir

2021-01-13T16:31:44.118Z

Yeah I was thinking of how to distribute this in a convenient way. I have more scripts like this in mind, so was actually thinking of a seperate repo. Maybe even installable via homebrew or something so it is easy to find and install

2021-01-13T16:32:18.118300Z

Also it becomes complex pretty quickly, so tests would be nice too

borkdude 2021-01-13T16:32:39.118500Z

well, maybe as a gitlib?

2021-01-13T16:33:31.118700Z

could be helpful when using it as a library. gitlib’s don’t support adding binaries to the PATH, right?

borkdude 2021-01-13T16:34:14.118900Z

well, you can check anything into git, but maybe not the best thing to do. why?

borkdude 2021-01-13T16:34:56.119100Z

what kind of binary?

2021-01-13T16:35:10.119300Z

just to make it a bit more convenient. Like how you install babashka through homebrew and not having to manage everything yourself (including updates)

2021-01-13T16:35:27.119500Z

a binary as in chmod +x script/my-babashka.clj

lukasz 2021-01-13T16:36:11.119700Z

btw, I'll most likely write my own version of the SSO provider, as for example - when configuring SSO you have to have a valid config with profiles - @jeroenvandijk version assumes that some of that is configured in source

👍 1
2021-01-13T16:36:13.119900Z

I’ll look into it later. For now, I spend way too much time on everything related to this pod 😅

borkdude 2021-01-13T16:37:07.120100Z

but this was also the pod / native aws thing you have tried to come up with for a long time... right? so not time wasted...?

💯 1
2021-01-13T16:37:09.120300Z

@lukaszkorecki My script only assumes you give it the right arguments in your credentials file (region, account-id, role and start url).

2021-01-13T16:38:06.120500Z

@borkdude sorry definitely didn’t mean wasted! Just that I need to focus a bit on other things and not sure when I’ll get to wrapping all these other things properly

borkdude 2021-01-13T16:39:14.120800Z

@jeroenvandijk if you are distributing .clj files, I think gitlibs are the way to go.

(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {jeroenvandijk/scripts {:git/url "<https://github>..." :sha "..."}}})
(require '[jeroenvandijk.scripts.aws-thing :as aws-thing])

2021-01-13T16:39:52.121Z

Yeah looks good! Thank you

borkdude 2021-01-13T16:42:32.121300Z

Btw, I automated bumping the aws-api deps using a bb script: https://github.com/babashka/pod-babashka-aws/blob/main/script/update-deps.clj

2021-01-13T16:44:31.121700Z

ah smart

borkdude 2021-01-13T16:46:09.121900Z

And we have already 5 contributors now in such a short time. I think it's a success. Thanks for the time you put into the credential stuff especially, the gnarliest bit :)

2021-01-13T16:48:33.122100Z

I have to thank for you sure! 🙏 For putting that much time in this and not even being a real AWS user (yet, right?)

borkdude 2021-01-13T16:49:09.122300Z

Right, but we're moving to the cloud now at work too, so I'll probably be one soon (either AWS, or Azure)

2021-01-13T16:49:20.122500Z

I’m also happy with the result. I have spent a lot of time in getting AWS tools to compile with Graalvm. This will not be the last one I think

2021-01-13T16:49:43.122700Z

Ah nice. Good to hear you can start with Clojure tools from the start (when using AWS)

steveb8n 2021-01-11T01:06:12.070300Z

has anyone done this i.e. tested that the creds provider works with Vault?

roklenarcic 2021-01-11T10:47:16.078Z

this is more related to sci, but can you interrupt (timeout) a sci.core/eval-string ?

borkdude 2021-01-11T10:48:41.078700Z

@roklenarcic you can do this by using the same strategy as nREPL does this: run it in a thread and use the (deprecated!) Thread#stop method

roklenarcic 2021-01-11T10:50:52.079100Z

In Java the new, non-obsolete, method for doing this is to check Thread/interrupted at various parts and end if it is so. Thread/stop can fail to free some resources. For instance in an interpreter like sci, it would be easy to check Thread/interrupted after each expression is evaluated.

roklenarcic 2021-01-11T10:51:47.079300Z

Future stopping and ExectorService shutdown also sends interrupted signal to the tasks

borkdude 2021-01-11T10:53:26.079500Z

This still won't catch things like (doall (range)) since it would require those functions to adopt the same strategy

borkdude 2021-01-11T10:53:37.079700Z

in clojure.core

roklenarcic 2021-01-11T11:18:39.079900Z

ah true

lgouger 2021-01-11T13:58:35.081200Z

Hoping this is useful and also looking for feedback.  paging-invoke a function to lazily call aws/invoke to page through large result sets. https://gist.github.com/lgouger/2262e2d2503306f2595e48a7888f4e73

🤘 3
lukasz 2021-01-11T14:49:35.082600Z

Another huge shoutout to bb - I was able to convert my legacy "full" Clojure project, which interacted with BigQuery, to just one file bb script (which uses bb.process and bq command line tool).

🎉 9