Fork me on GitHub
Jamie Rumbelow14:08:43

Today is the first day that I write Clojure professionally; for real money 😍

parrot 32
🎉 40
aw_yeah 24
🙌 16
metal 8
📈 4
Ashley Smith15:08:10

Hey, so it is now time for me to learn about security - I know this is an absolutely HUGE topic for the scope of this slack, but I wanted to know if anyone here had used buddy for creating sign in tokens? My goal is to have the user submit their username and password once and only once, receive a token that is valid for a certain amount of time, and use that for all further communication. However, having never touched security before, I'm trying to find my entry point. Is buddy-sign a good package for this? Tough position to be in

Ashley Smith15:08:24

im probably going to follow this, just intimidated


The Signed JWT Auth Example is probably what you'd want?

Ashley Smith15:08:03

It sounds like it but im not quite sure how it truly works

Alex Miller (Clojure team)15:08:06

@ashley this is not an answer to your question, but I think it's a great high-level talk about key topics in web security for Clojure apps per OWASP

Ashley Smith15:08:23

I'll give it a watch as that sounds like something I need to see

Alex Miller (Clojure team)15:08:47

it will give you a map for thinking about it at least

Ashley Smith15:08:59

I'm not sure about the 'self contained' part of the JWT auth example, if the client doesn't accept the token, how does the server distinguish between clients?


what do you mean by "if the client doesn't accept the token"?

Ashley Smith15:08:54

This type of token mechanism enables a complete stateless authentication because the server does not need to store the token and related information, the token will contain all the needed information for authentication.
So, I don't understand this because it refers to this needed information, but I don't know what exactly this is


so the idea here is to just allow allowed clients to talk to the server. the token is digitally signed by the server before handing it out. all subsequent requests must have this

Ashley Smith15:08:27

my understanding is that a token is like a temporary password. You sign in and you get given a token for your use of the site. When you request data you use your token - but if everything is self contained on the server, what does the client get from signing in, and how is the server stateless if it is actually managing the currently active tokens

Ashley Smith15:08:41

So the token is still given out?

dharrigan15:08:49 is a good start for understanding jwt


if the client has valid creds


the user ID is contained directly in the token information, and as long as the token is signed by the server, the server can trust its own signatures

Ashley Smith15:08:11

yeah, I'll go watch some videos that people have recommended as it seems these kinds of guides expect a basic understanding of the terminology otherwise I'll fail to understand the details like we just discussed. When it said everything is self contained. I was thinking it was referring to the server, not the token. Okay I get it

Ashley Smith15:08:19

Thank you for giving me a head start!


JSON web tokens are controversial

☝️ 4

Read about the controversy, it will prevent accidents 🙂


But you can ignore all of the specifics about JSON web tokens and think: encrypt(key, data_payload) == token

Ashley Smith15:08:06

controversial as in.. I shouldn't be learning to use them, or just that there has been and that its okay to use?


oh, sorry this is #clojure -- (let [token (encrypt key data)]...)


Depends on which security professional you talk to, but in the early days of JWTs, many of the libraries had terrible defaults.


Anything that tells you to make RSA openssl keys is suspect


you can use symmetric encryption to do these tokens ^^


all the backend servers will share the symmetric key -- which is another risk vector


do you know how many backends you'll have?

Ashley Smith15:08:19

That buddy page says this:

In order to use any asymmetric encryption algorithm, you should have private/public key pair. If you don’t have one, don’t worry, it is very easy to generate it using openssl, see this faq entry.
You think I should ignore that advice and do something else?


Nothing about this necessitates JWTs, or assymmetric encryption

Ashley Smith15:08:13

Hmm, no. In terms of types, I have a database server, my API server and my frontend server. In the future people might want multiple quantities of each but I'd have to learn docker swarms first. I'm taking it slow and doing one of each - but I don't know if I need new servers for this stuff


you type so fast, I'm impressed


conceptually, the server must be able to validate a token it is presented


can be signed with asymmetric encryption, or encrypted with a symmetric key

Ashley Smith15:08:58

Haha 🙂 I guess you could say I'm a little chatty because it's how I mainly learn - as you can probably gather from the amount of questions I ask here

Ashley Smith15:08:26

I also never take my fingers off the keyboard so I'm kind of just used to keybindings and doing things fairly quick

Ashley Smith15:08:31

Im eating lunch now though so taking it easy, then I'll watch those videos and have a shower while I think about my plan of attack


server receives and checks user/pw, returns to user (sign key {:user/id 42})


that's all a stateless token is

Ashley Smith15:08:56

Thank you very very much 🙂 I really cannot wait to get over this hurdle as its kind of the last big 'thing' I haven't touched, after this it should be game over 🙂


If you use JWTs over session cookies for authentication, there are a couple things to look out for: - Server-side rendering just became impossible because JWTs stored in local/session storage have to be sent with an XHR request - If you provide downloads that require the user to be authenticated, you will have to either guarantee that downloads are small enough to use something like URL.createObjectURL in the browser, or you will have to generate short-lived, one-off URLs that do not require authentication - Local/session storage are not actually secure. If a JWT is stored in session storage, then entering sessionStorage in the Chrome dev tools will output all session storage tokens, making it possible to hijack a JWT from one user, call sessionStorage.setItem('{key}', '{other_users_jwt}') in dev tools for another session, and effectively be logged in as the first user. There are probably ways around this, but IMO it’s better to use session cookies.

👏 4
Ashley Smith16:08:00

thank you for the heads up!! 🙂

David Pham16:08:24

What is the state of a Clojure targeting .NET


It exists. David Miller does a lot of work on it to bring it up to date with features added to Clojure/Java version. According to Clojure surveys, it is used by a fairly small fraction of Clojure developers (about 2% of those who responded to 2019 survey). I personally have not used .NET for developing anything, Clojure or otherwise, so am not the right person to give more details.

David Pham17:08:21

Would it be safe to develop anything with it?

Alex Miller (Clojure team)17:08:06

depends how you measure safety :)

Alex Miller (Clojure team)17:08:22

afaik it works and is a reasonable close port of the jvm version

Alex Miller (Clojure team)17:08:00

the number of users is quite small though. the arcadia unity project is easily the biggest thing I know of based on it

Alex Miller (Clojure team)17:08:13

(I do not know of anything else)

David Pham17:08:09

Do you think support will drop at some point?


@seancorfield: I'm using depstar along with a process to do AOT in preparation to create a native-image with the GraalVM.


{:deps {org.clojure/clojure {:mvn/version "1.10.1"}}
 :aliases {:aot {:extra-paths ["classes"]
                 :main-opts ["-e" "(compile,'clj-graalvm.core)"]}
           :depstar {:extra-deps {seancorfield/depstar {:mvn/version "0.3.1"}}}}}
and I can generate the jar with:
clojure -A:depstar:aot -m hf.depstar.uberjar clj-graalvm.jar -m clj_graalvm.core -v
and run it:
java -jar clj-graalvm.jar
👋 1.10.1
but, I can't produce a native-image:
native-image --report-unsupported-elements-at-runtime --initialize-at-build-time -jar clj-graalvm.jar
Build on Server(pid: 41171, port: 57235)
[clj-graalvm:41171]    classlist:   1,114.78 ms
[clj-graalvm:41171]        (cap):     942.79 ms
[clj-graalvm:41171]        setup:   1,165.54 ms
[clj-graalvm:41171]     analysis:   4,439.00 ms
Warning: Aborting stand-alone image build. Class initialization of clj_graalvm.core failed. Use the option --initialize-at-run-time=clj_graalvm.core to explicitly request delayed initialization of this class.
Detailed message:

Warning: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
Build on Server(pid: 41171, port: 57235)
[clj-graalvm:41171]    classlist:     139.48 ms
[clj-graalvm:41171]        (cap):     927.01 ms
[clj-graalvm:41171]        setup:   1,141.24 ms
[clj-graalvm:41171]   (typeflow):   1,248.20 ms
[clj-graalvm:41171]    (objects):   1,359.97 ms
[clj-graalvm:41171]   (features):     104.56 ms
[clj-graalvm:41171]     analysis:   2,760.68 ms
[clj-graalvm:41171]     (clinit):      67.37 ms
[clj-graalvm:41171]     universe:     142.82 ms
[clj-graalvm:41171]      (parse):     218.14 ms
[clj-graalvm:41171]     (inline):     542.06 ms
[clj-graalvm:41171]    (compile):   1,023.42 ms
[clj-graalvm:41171]      compile:   1,923.44 ms
[clj-graalvm:41171]        image:     213.90 ms
[clj-graalvm:41171]        write:     130.16 ms
[clj-graalvm:41171]      [total]:   6,488.63 ms
Warning: Image 'clj-graalvm' is a fallback image that requires a JDK for execution (use --no-fallback to suppress fallback image generation).


native-image and clojure 1.10.1 are not compatible @johnjelinek


which version should I be using?


dunno - ask in #graalvm


has nothing to do with depstar


native-image is some weird relative to the JVM, doesn't support full Java


I just wanna make a few simple single-binary non-JVM CLI apps


I’m having difficulties making a multipart POST request with http-kit to the google drive rest api. Everything works with Postman, but I can’t figure out the configuration with http-kit/post or http-kit/request. Has anyone done this?


I’m working on a PR for a library, and I’d like to test it locally in a different deps.edn project. However, I can’t quite figure out what the best way to require the local copy. Are people using deps :aliases for that?


I’ve tried the :alias approach, but the library is a lein project and I’m getting Manifest type not detected when finding deps


not sure how to resolve


Ah, I just needed to run lein pom


What's the difference b/w vars and atoms?


How is alter-var-root diff. from swap!, except from the retry in the atom case?


What happens when multiple threads try to alter a var root and fail?


alter-var-root doesn't fail AFAIK, it's just serialized?


swap! is faster if lack of contention is the common case


alter-var-root just locks while updating so the contender has to wait


it's slower thanks to the lock (which an atom doesn't need)


@jaihindhreddy have you read this page? it tries to explain how var differs from the other mutable types (I thought it explained all four but they're spread across multiple pages)


Read this page and the atom page before posting here but still didn't get it. Now I understand that alter-var-root locks the var whereas atom leverages CAS with retries.


There's also the per-thread dynamic aspect of vars


alter-var-root calls out to this, which thanks to synchronized uses locking implicitly

👍 4

swap! calls this, no locking or synchronization (uses compareAndSet and retries until success instead)

💯 4

@seancorfield: I'm using and encountering interesting behavior:

(defn default-repository-name []
  (->> (clojure.string/split (-> ( ".") .getAbsolutePath) #"/")
I was expecting that if I ran my application from different locations, then the default would render differently:
$ pwd

$ ../vault-policy-generator -h
This reviews your repository and spits out appropriate vault policies.

Usage: vault-policy-generator [options]

  -d, --database NAME                          Database Name
  -n, --name NAME      vault-policy-generator  Repository name
  -h, --help
I was expecting it to say -n, --name NAME wat Repository name ☝️
(def cli-options
  [["-d" "--database NAME" "Database Name (web or pos)"]
   ["-n" "--name NAME" "Repository name"
    :default (default-repository-name)]
   ["-h" "--help"]])


@johnjelinek you built an uberjar?


(With AOT I'm guessing)


def computes the value at compile time


So AOT compiles it and that's the value it gets for all time.


What's the right way to tell to to come up with this value at runtime?


Build the uberjar WITHOUT AOT and it will do what you want


But then you'll need to run it differently


(I'm on vacation in England so I'm typing on my phone -- explanation is limited 😁)

😮 4

Is there a way to keep AOT and still allow this to be evaluated at runtime?


OH! 😆 we don't have to figure this out right now, go vacation!


Make it a defn with no args and call it


At work we just don't use AOT at all


OH! 😆 good catch!


😆 that's why I'm in #beginners