chris613
2019-9-26 07:52:21

@soegaard2 my personal preference, when i see “log in with x” it annoys me when im then asked to create a 2nd set of credentials. usually im using the federated login feature because i dont want to come up with new credentials for that specific service.


soegaard2
2019-9-26 10:44:01

Thanks for the input everyone - I have something to think about.


soegaard2
2019-9-26 14:21:44

The code github authentication needs to know the a “client secret”. Other authentication methods will require other secrets. I have put the encrypted secrets in a file “secret.rkt”. (The source is public, so I can’t put the unencrypted secrets in the file). This way I need to handle only one secret key on the server.

Is this a reasonable idea? And have I made any mistakes?

https://github.com/soegaard/web-tutorial/blob/master/listit4/app-racket-stories/secret.rkt


samth
2019-9-26 14:33:30

I usually have the secret in a file that I read in with file->value and that is not checked in


jaz
2019-9-26 14:52:40

It’s also very common to put these in environment variables.


samth
2019-9-26 14:53:49

Right. @popa.bogdanp’s recent post talked about some of that and @lexi.lambda had a post/library that related to that as well.



samth
2019-9-26 14:57:35

yes


soegaard2
2019-9-26 15:12:13

There are pros and cons.

Files are simple - but there is a risk committing them by accident.

Environment: No risk of committing the values, but the secret keys are no longer part of the repo. (Also I am unsure how to handle the setting of these in a secure way - use a shell script?)


samth
2019-9-26 15:20:18

It’s often done in an encrypted interface in the hosting environment


samth
2019-9-26 15:20:26

see Travis secrets, for example


samth
2019-9-26 15:20:31

or Github actions


soegaard2
2019-9-26 15:29:20

Thanks for the pointers.


soegaard2
2019-9-26 15:29:41

Hadn’t looked at Github Actions before.


samth
2019-9-26 15:29:58

Bogdan uses Procfiles for things related to this, and recently released a racket implementation of them


samdphillips
2019-9-26 17:33:39

There are also things like Vault for holding/accessing/managing secrets.


soegaard2
2019-9-26 17:34:15

samdphillips
2019-9-26 17:38:24

yes that is it.


soegaard2
2019-9-26 17:40:51

I am pleasantly surprised it is free for open source - but a bit scared that they don’t list prices for business.


conrad.steenberg
2019-9-26 17:52:13

Ansible also has a vault file format, which is stored encrypted, and decrypted upon deployment, no service API needed


soegaard2
2019-9-26 17:59:31

Am I reading the Vault page incorrectly? Is the open source version free for all (including business) ?


conrad.steenberg
2019-9-26 18:12:43

Yes, it’s using the MPLv2 license :+1:


soegaard2
2019-9-26 18:13:03

Cool.


notjack
2019-9-26 18:14:15

how are you planning on deploying your project?


soegaard2
2019-9-26 18:14:53

A server on Digital Ocean.


soegaard2
2019-9-26 18:16:29

Nginx in front of the racket web-server(s).


soegaard2
2019-9-26 18:16:40

(Practising for another project)


notjack
2019-9-26 18:20:29

If you happen to already be using docker for any parts of this, Docker Swarm has a built-in secrets system where they look like regular files that your app reads. But swarm keeps them in memory and encrypted at rest and in transit.


soegaard2
2019-9-26 18:22:41

That sounds elegant. Do Docker containers work the same way as Droplets?


notjack
2019-9-26 18:24:39

No, each container acts more like a process than like a VM. It takes some getting used to.


notjack
2019-9-26 18:28:56

You’d want to put nginx and your racket webserver in separate containers, for example. Then Swarm could horizontally scale them separately.


notjack
2019-9-26 18:30:19

I wouldn’t recommend going down this route unless you’re willing to set aside some time for learning docker. Not using it for this is perfectly reasonable.


chris613
2019-9-26 18:30:36

i usually foloow this @soegaard2 https://12factor.net


chris613
2019-9-26 18:31:20

served me well for my career so http://far.in\|far.in this case it would let the secret management be decoupled from the application (i.e. you can use whatever technique you like to get the secret into an env var)


soegaard2
2019-9-26 18:32:58

@chris613 Great set of guide lines.


chris613
2019-9-26 18:33:57

yeah it was onrignally a heroku blog post i think. like i said its been my own little bible for applications in production for many years, and ive seen a LOT of other setups that were way more complex & way more simple but ultimately harder to maintain


soegaard2
2019-9-26 18:34:23

If I need to change hosting at some point, then Docker would make it easy.


soegaard2
2019-9-26 18:34:52

The tools at DigitalOcean is directed at Droplets (VMs) though.


chris613
2019-9-26 18:35:11

i think this was the original one i read https://blog.heroku.com/twelve-factor-apps


soegaard2
2019-9-26 18:35:12

I am not quite sure how running Docker containers on DO work.


chris613
2019-9-26 18:37:05

i just set down to read your post linked here @lexi.lambda and see you had beaten me to the 12factor referencing :wink:


samth
2019-9-26 18:44:09

@soegaard2 you’d just run the docker program on your droplet


soegaard2
2019-9-26 18:44:25

That’s it?!


notjack
2019-9-26 18:53:28

Yes! With one caveat: Docker and Docker Swarm are two different things. Swarm is the official system for running a cluster of containers and restarting them when anything dies. To use Swarm, you’d run docker swarm init in your droplet.


soegaard2
2019-9-26 19:03:55

Deja vu. I had forgotten that DO has Kubernetes. I ignored them because the cheapest is 10$ a month and the cheapest droplet is 5$ a month.


soegaard2
2019-9-26 19:04:18

I didn’t realize I could use Docker from within a droplet.


notjack
2019-9-26 19:12:13

For context, Swarm and Kubernetes do roughly the same things. Kubernetes can do a lot more but it’s also much more complicated. Your average small web app almost certainly doesn’t need it.


soegaard2
2019-9-26 19:14:55

I’ll put it on my (fast growing) list of things to read up on.


soegaard2
2019-9-26 19:15:44

Right now I don’t have a real sense of how many users / how much traffic a single web-server can handle.


notjack
2019-9-26 19:18:53

Most web apps are IO-bound, not CPU-bound, so database performance should be your bottleneck and not webserver performance. If it seems like the webserver is too slow, there’s a good chance its code is just blocking on things it shouldn’t be.


notjack
2019-9-26 19:19:25

Or it has a memory leak somewhere


soegaard2
2019-9-26 19:23:42

Apropos performance - is there a package that keeps track of the average response times of different routes?


notjack
2019-9-26 19:24:11

I don’t think so :(


notjack
2019-9-26 19:24:50

There is a package for reporting webserver exceptions to Sentry


soegaard2
2019-9-26 19:25:04

Maybe there is an add-on for nginx ?


notjack
2019-9-26 19:25:15

(thanks Bogdan!)


notjack
2019-9-26 19:25:17

Probably


notjack
2019-9-26 19:26:02

If you’re interested in that kind of data and monitoring, you might want to set up Prometheus


notjack
2019-9-26 19:27:04

It’s a database for timeseries data and metrics. A lot of tools can export metrics about themselves to Prometheus, including docker.


notjack
2019-9-26 19:27:53

There’s probably an add-on to nginx to export various useful timing statistics to Prometheus.


soegaard2
2019-9-26 19:36:59

Thanks for the tip.


alexharsanyi
2019-9-26 22:34:17

@soegaard2 the technique I used in my application is to define the keys in environment variables when I build the application and embed them in the compiled code using a macro like so:

(define-syntax (embedded-api-key stx)
  (syntax-case stx ()
    [_ #`(quote #,(getenv "AL2DSAPIKEY"))]))
(define (builtin-api-key) (embedded-api-key))

The resulting executable (or byte code files) now have the key inside and you don’t need to worry about acciedentally pushing the keys to the repository singe git cannot (yet) version control environment variables.

The disadvantage is that you’ll have to re-build the application if the key changes, but they don’t change very often.


soegaard2
2019-9-26 22:46:02

@alexharsanyi I like that solution!


notjack
2019-9-26 23:33:52

wait, doesn’t that mean your app’s bytecode will contain the key in a way that can be extracted?


lexi.lambda
2019-9-27 00:05:19

I suppose whether or not that matters to you depends on your approach to deployment and your threat model


alexharsanyi
2019-9-27 00:05:25

Yes. Do you know how to extract it?

My use case is shipping a built application with a private API key that users can install on their own machines. Sure, I could encrypt the key, but that you can than just extract the encryption key. I am interested to know how others do it, but my impression is that the only applications that are not cracked are the ones that are not worth cracking :slightly_smiling_face: , so I settled for a good enough solution not for a perfect solution. I can also revoke the API keys if they become compromised, although in my case, I am just use the free tier of them, so it might be simpler for someone just to get a free set of API keys for themselves than extract them from my application.

And for a web service it does not matter as most users won’t have access to the binary anyway — of course this solution does not work if your application uses different keys for staging and production.


notjack
2019-9-27 01:31:11

for desktop apps you’re totally right that it’s not a security issue, yeah


notjack
2019-9-27 01:31:52

since there is no possible way to keep any secrets needed by the app out of the hands of its user


ryanc
2019-9-27 01:34:02

The OAuth2 RFC acknowledges that installed applications can’t keep secrets: https://tools.ietf.org/html/rfc6749#section-2.1. My brief and not-recent OAuth2 experience is mostly with Google, and they treat installed applications slightly differently from server-side applications. Seems like github wants to ignore them, though.


pocmatos
2019-9-27 06:48:03