SlideShare a Scribd company logo
Or,“why do we keep baking secrets into our artifacts?”
Symfony finally
swiped right on
envvars
Or,“why do we keep baking secrets into our artifacts?”
Symfony finally
swiped right on
envvars
just a collection of
cool gifs
Symfony finally swiped right on envvars
Hi, I’m Sam
● Long time listener, first time caller.
● Co-organiser of this group.
● Using Symfony since 2.0 beta.
● Day job - ops @ REA.
● Docker & build automation fanboy.
● Have committed terrible atrocities with VCS and
build systems in the past.
Symfony is
not your grandma’s
framework
unique as a web framework
Most frameworks
re-read config at
boot.
(Every. page. load.)
$ bin/elasticsearch
...waits 30 seconds...
$ curl localhost:9200
[timeout]
...waits 30 more seconds...
$ curl localhost:9200
[timeout]
Symfony compiles
the DI container to
PHP, including all
config values.
Let’s talk about
secrets, baby.
What is a secret?
Symfony finally swiped right on envvars
● Database credentials
● SMTP creds
● Payment gateway keys
● AWS credentials
● SMS tokens
● EDM service API keys
Beyond 11 herbs and spices
The modern app has so many..
● S3 bucket names
● SSH or deploy keys
● JWT keys or certificates
● Service n’s API key
● Other internal system hostnames
But really, an application secret is anything you wouldn’t
put directly in the HTML markup itself.
Here’s why we get a bad
rep as php developers[1][2]
…
1: I’ve seen all of these examples used
2: you probably have, too
Symfony finally swiped right on envvars
<?php
class Config {
const LIVE_DATABASE_STRING = 'mysql://root:root@localhost:3306/pro
const TEST_DATABASE_STRING = 'mysql://root:root@localhost:3306/tes
public static function getDatabaseString() {
// @TODO add magic to determine environment
return self::LIVE_DATABASE_STRING;
}
// ...etc
The know it all “pattern”
The build it & they’ll come “pattern”
1. put your prod & test values in a config file
2. run “make config” or some other magic build script
3. generate PHP from template:
<?php
class Config {
const DATABASE_STRING = '{{ database_string }}';
public static function getDatabaseString() {
return self::DATABASE_STRING;
Symfony finally swiped right on envvars
dropping a prod
database on a
misconfigured
test site. - my biggest professional fuck up.
probably?
config_dev.yml:
doctrine:
dbal:
url: 'mysql://root:root@localhost:3306/dev'
The config.yml is the new Config
class…. “pattern”
config_prod.yml:
doctrine:
dbal:
url: 'mysql://root:fk!ash#@localhost:3306/pr
Into today*...
* as is common in many
Symfony projects
Symfony finally swiped right on envvars
Note: This is the best of the bad, but Symfony makes it insecure & hard to
update.
1. define your config keys in a file called parameters.yml.dist, set sane defaults
2. store the actual configuration on S3 / build servers / CI / somewhere else
3. at build-time, copy the file in & build the container (cache-warm)
The Fabien told me to “pattern”
Symfony finally swiped right on envvars
OK. What’s
wrong with this?
How secure is your CI?
Who has access to wherever the
parameter values are stored?
OK. What’s
wrong with this?
Rolling the keys means re-deploying
the application.
OK. What’s
wrong with this?
Secrets are written into the
compiled Container class file.
Try it yourself:
$ grep “database.host”
var/cache/prod/*.php
OK. What’s
wrong with this?
Creating new deployments is hard.
OK. What’s
wrong with this?
Production artifact differs to test.
OK, so what’s the answer?
Symfony finally swiped right on envvars
Introducing environment variables
✅ Easy to set up in the app
✅ Functions just like another parameter
✅ Not compiled into the container
✅ Like other parameters, allows default values to be set
✅ Updating values is as simple as updating wherever it’s
stored & reload PHP
Introducing environment variables
❌ Can’t access outside services - i.e. controllers etc -
may require app refactoring
❌ Can be difficult to implement if you run your app
outside of Docker
❌ Some libraries don’t quite support envvars yet
(there’s a workaround though!)
Porting an existing
app is easy.
parameters:
env(DATABASE_URL): mysql://root:root@db:3306/symfony?charset=
env(MAILER_HOST): smtp.sparkpostmail.com
env(MAILER_PORT): 587
env(MAILER_USER): SMTP_Injection
env(MAILER_PASS):
env(SECRET): ThisTokenIsNotSoSecretChangeIt
short_link_host: %env(SHORT_LINK_HOST)%
env(SHORT_LINK_HOST): fallback.local
Default values, get overridden if provided in the
env
How I dealt with libraries that don’t support env vars or
values needed in controllers
Note the structure
around the name
doctrine:
dbal:
url: '%env(DATABASE_URL)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
swiftmailer:
transport: "smtp"
host: "%env(MAILER_HOST)%"
port: "%env(MAILER_PORT)%"
username: "%env(MAILER_USER)%"
password: "%env(MAILER_PASS)%"
spool: { type: "memory" }
How they’re used - in configuration YAML files...
services:
amazon_s3:
class: AwsS3S3Client
arguments:
- credentials:
key: "%env(AWS_ACCESS_KEY_ID)%"
secret: "%env(AWS_ACCESS_SECRET_KEY)%"
region: "%env(AWS_REGION)%"
version: "2006-03-01"
How they’re used - in service configuration files...
While you’re porting
● Consider what values actually change between
deployment environments
● Anything that doesn’t change, should go into
config.yml, config_dev.yml or
config_prod.yml (a la current standard edition
practice).
● Anything that changes is a good candidate to live in
the environment.
Any gotchas?
● Need to defer making decisions on anything that
changes per-deployment until later.
i.e. any decisions made in a container extension.
● Dynamic parameters don’t solve this
%param% => %env(PARAM)%
● If it’s your bundle/extension, you can use factory
services to work around this.
The Dotenv component in 3.3
● Symfony flex uses it out of the box!
● A small class that is added in your app/app_dev.php
and console scripts
● Provides env-var like support in places you can’t
easily set variables (dev!)
● In Flex, it replaces the parameters.yml paradigm
● Relatively easy to back-port into the full-stack
framework
Or…
Symfony finally swiped right on envvars
You can use docker
in development!
Symfony finally swiped right on envvars
It’s not (all) about
security.
Symfony finally swiped right on envvars
Environment vars are not perfect
● Does not solve security for anyone with access to the machine.
● Can still be accessed from outside your app - i.e. anything in
shell_exec() calls.
● The PHP user or someone on CLI can expose to another program.
● Any insecure libraries in your app can access it, too.
● Can unintentionally turn up in logs, the Symfony profiler, etc.
● The plain-text values are probably still stored somewhere.
How do I make it better?
● Current PR: github/symfony/symfony#23901 (due 3.4) adds features to
support docker/kubernetes secrets & make it extendable.
● Once it’s available to us, it might be like this…
○ on AWS? KMS-encrypted envvars or SSM Param. Store.
○ Not AWS? G-Cloud KMS, or other open-source, e.g. Hashicorp
Vault, Pinterest Knox, Lyft Confidant.
● In the meantime: do you host on AWS? Use KMS-encrypted environment
variables or fetch from SSM Param. Store at container boot.
● Any of these principles a surprise? Read about 12-factor apps
● Segment have a great write-up on managing secrets on AWS on their
blog.
● KMS-ed envvars (enc. strings): REA’s Shush is a tiny go library to help.
● SSM param. store (central management): Segment’s Chamber can help.
● Taking inspo from k8s, Docker swarm mode now has secrets built-in.
● Not using Docker? Can be quite complicated to set env across multiple
users + daemons. Apache, and CLI users share a syntax, PHP-FPM is
different.
● Example of porting a Symfony app to Docker - for the adventurous.
Further reading & tools
thank you.
stalky stalk: @sammyjarrett or linkedin.com/in/samjarrett
more detail and these slides
published at samjarrett.com.au/swipe-right

More Related Content

What's hot (20)

PPTX
201904 websocket
월간 IT 슬라이드
 
PPTX
Go Faster with Ansible (AWS meetup)
Richard Donkin
 
PDF
Ansible v2 and Beyond (Ansible Hawai'i Meetup)
Timothy Appnel
 
PDF
Ansible 2.0 - How to use Ansible to automate your applications in AWS.
Idan Tohami
 
PDF
快快樂樂用Homestead
Chen Cheng-Wei
 
PPTX
IaC and Immutable Infrastructure with Terraform, Сергей Марченко
Sigma Software
 
PDF
Vagrant for real (codemotion rome 2016)
Michele Orselli
 
PPTX
Introduction to vSphere APIs Using pyVmomi
Michael Rice
 
PDF
Getting started with Ansible
Ivan Serdyuk
 
ODP
Fabric: A Capistrano Alternative
Panoptic Development, Inc.
 
PDF
Deployment automation
Riccardo Lemmi
 
PDF
Create Development and Production Environments with Vagrant
Brian Hogan
 
PDF
Instruction: dev environment
Soshi Nemoto
 
PDF
Getting Started with Ansible
Ahmed AbouZaid
 
PDF
Application Deployment Using Ansible
Cliffano Subagio
 
PPT
Local Dev on Virtual Machines - Vagrant, VirtualBox and Ansible
Jeff Geerling
 
PDF
EC2 AMI Factory with Chef, Berkshelf, and Packer
George Miranda
 
PDF
Ansible best practices
StephaneFlotat1
 
PPT
Learn basic ansible using docker
Larry Cai
 
PDF
From Dev to DevOps - Codemotion ES 2012
Carlos Sanchez
 
201904 websocket
월간 IT 슬라이드
 
Go Faster with Ansible (AWS meetup)
Richard Donkin
 
Ansible v2 and Beyond (Ansible Hawai'i Meetup)
Timothy Appnel
 
Ansible 2.0 - How to use Ansible to automate your applications in AWS.
Idan Tohami
 
快快樂樂用Homestead
Chen Cheng-Wei
 
IaC and Immutable Infrastructure with Terraform, Сергей Марченко
Sigma Software
 
Vagrant for real (codemotion rome 2016)
Michele Orselli
 
Introduction to vSphere APIs Using pyVmomi
Michael Rice
 
Getting started with Ansible
Ivan Serdyuk
 
Fabric: A Capistrano Alternative
Panoptic Development, Inc.
 
Deployment automation
Riccardo Lemmi
 
Create Development and Production Environments with Vagrant
Brian Hogan
 
Instruction: dev environment
Soshi Nemoto
 
Getting Started with Ansible
Ahmed AbouZaid
 
Application Deployment Using Ansible
Cliffano Subagio
 
Local Dev on Virtual Machines - Vagrant, VirtualBox and Ansible
Jeff Geerling
 
EC2 AMI Factory with Chef, Berkshelf, and Packer
George Miranda
 
Ansible best practices
StephaneFlotat1
 
Learn basic ansible using docker
Larry Cai
 
From Dev to DevOps - Codemotion ES 2012
Carlos Sanchez
 

Similar to Symfony finally swiped right on envvars (20)

PDF
A dive into Symfony 4
Michele Orselli
 
PDF
Containerizing legacy applications
Andrew Kirkpatrick
 
PDF
Symfony 4: A new way to develop applications #phpsrb
Antonio Peric-Mazar
 
PDF
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
Fabien Potencier
 
PDF
Fabien Potencier "Symfony 4 in action"
Fwdays
 
PDF
Configuring Symfony
gueste3cfbb
 
PDF
Configuring Symfony
Wildan Maulana
 
PDF
Word press, the automated way
Michaël Perrin
 
PDF
Deploying Symfony | symfony.cat
Pablo Godel
 
PDF
Preparing your dockerised application for production deployment
Dave Ward
 
PDF
Symfony2 revealed
Fabien Potencier
 
PDF
Modern Gentlemen's WordPress
Enrico Deleo
 
PDF
Symfony quick tour_2.3
Frédéric Delorme
 
PDF
Kubernetes Hands-On Guide
Stratoscale
 
PDF
Php through the eyes of a hoster
Combell NV
 
PDF
Symfony 4: A new way to develop applications #ipc19
Antonio Peric-Mazar
 
PDF
Dockerize your Symfony application - Symfony Live NYC 2014
André Rømcke
 
PDF
Symfony workshop introductory slides
Stefan Koopmanschap
 
PDF
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
Ryan Weaver
 
PDF
eZ Publish 5: from zero to automated deployment (and no regressions!) in one ...
Gaetano Giunta
 
A dive into Symfony 4
Michele Orselli
 
Containerizing legacy applications
Andrew Kirkpatrick
 
Symfony 4: A new way to develop applications #phpsrb
Antonio Peric-Mazar
 
symfony: An Open-Source Framework for Professionals (Dutch Php Conference 2008)
Fabien Potencier
 
Fabien Potencier "Symfony 4 in action"
Fwdays
 
Configuring Symfony
gueste3cfbb
 
Configuring Symfony
Wildan Maulana
 
Word press, the automated way
Michaël Perrin
 
Deploying Symfony | symfony.cat
Pablo Godel
 
Preparing your dockerised application for production deployment
Dave Ward
 
Symfony2 revealed
Fabien Potencier
 
Modern Gentlemen's WordPress
Enrico Deleo
 
Symfony quick tour_2.3
Frédéric Delorme
 
Kubernetes Hands-On Guide
Stratoscale
 
Php through the eyes of a hoster
Combell NV
 
Symfony 4: A new way to develop applications #ipc19
Antonio Peric-Mazar
 
Dockerize your Symfony application - Symfony Live NYC 2014
André Rømcke
 
Symfony workshop introductory slides
Stefan Koopmanschap
 
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
Ryan Weaver
 
eZ Publish 5: from zero to automated deployment (and no regressions!) in one ...
Gaetano Giunta
 
Ad

Recently uploaded (20)

PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
July Patch Tuesday
Ivanti
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Ad

Symfony finally swiped right on envvars

  • 1. Or,“why do we keep baking secrets into our artifacts?” Symfony finally swiped right on envvars
  • 2. Or,“why do we keep baking secrets into our artifacts?” Symfony finally swiped right on envvars just a collection of cool gifs
  • 4. Hi, I’m Sam ● Long time listener, first time caller. ● Co-organiser of this group. ● Using Symfony since 2.0 beta. ● Day job - ops @ REA. ● Docker & build automation fanboy. ● Have committed terrible atrocities with VCS and build systems in the past.
  • 5. Symfony is not your grandma’s framework unique as a web framework
  • 6. Most frameworks re-read config at boot. (Every. page. load.)
  • 7. $ bin/elasticsearch ...waits 30 seconds... $ curl localhost:9200 [timeout] ...waits 30 more seconds... $ curl localhost:9200 [timeout]
  • 8. Symfony compiles the DI container to PHP, including all config values.
  • 10. What is a secret?
  • 12. ● Database credentials ● SMTP creds ● Payment gateway keys ● AWS credentials ● SMS tokens ● EDM service API keys Beyond 11 herbs and spices
  • 13. The modern app has so many.. ● S3 bucket names ● SSH or deploy keys ● JWT keys or certificates ● Service n’s API key ● Other internal system hostnames But really, an application secret is anything you wouldn’t put directly in the HTML markup itself.
  • 14. Here’s why we get a bad rep as php developers[1][2] … 1: I’ve seen all of these examples used 2: you probably have, too
  • 16. <?php class Config { const LIVE_DATABASE_STRING = 'mysql://root:root@localhost:3306/pro const TEST_DATABASE_STRING = 'mysql://root:root@localhost:3306/tes public static function getDatabaseString() { // @TODO add magic to determine environment return self::LIVE_DATABASE_STRING; } // ...etc The know it all “pattern”
  • 17. The build it & they’ll come “pattern” 1. put your prod & test values in a config file 2. run “make config” or some other magic build script 3. generate PHP from template: <?php class Config { const DATABASE_STRING = '{{ database_string }}'; public static function getDatabaseString() { return self::DATABASE_STRING;
  • 19. dropping a prod database on a misconfigured test site. - my biggest professional fuck up. probably?
  • 20. config_dev.yml: doctrine: dbal: url: 'mysql://root:root@localhost:3306/dev' The config.yml is the new Config class…. “pattern” config_prod.yml: doctrine: dbal: url: 'mysql://root:fk!ash#@localhost:3306/pr
  • 21. Into today*... * as is common in many Symfony projects
  • 23. Note: This is the best of the bad, but Symfony makes it insecure & hard to update. 1. define your config keys in a file called parameters.yml.dist, set sane defaults 2. store the actual configuration on S3 / build servers / CI / somewhere else 3. at build-time, copy the file in & build the container (cache-warm) The Fabien told me to “pattern”
  • 25. OK. What’s wrong with this? How secure is your CI? Who has access to wherever the parameter values are stored?
  • 26. OK. What’s wrong with this? Rolling the keys means re-deploying the application.
  • 27. OK. What’s wrong with this? Secrets are written into the compiled Container class file. Try it yourself: $ grep “database.host” var/cache/prod/*.php
  • 28. OK. What’s wrong with this? Creating new deployments is hard.
  • 29. OK. What’s wrong with this? Production artifact differs to test.
  • 30. OK, so what’s the answer?
  • 32. Introducing environment variables ✅ Easy to set up in the app ✅ Functions just like another parameter ✅ Not compiled into the container ✅ Like other parameters, allows default values to be set ✅ Updating values is as simple as updating wherever it’s stored & reload PHP
  • 33. Introducing environment variables ❌ Can’t access outside services - i.e. controllers etc - may require app refactoring ❌ Can be difficult to implement if you run your app outside of Docker ❌ Some libraries don’t quite support envvars yet (there’s a workaround though!)
  • 35. parameters: env(DATABASE_URL): mysql://root:root@db:3306/symfony?charset= env(MAILER_HOST): smtp.sparkpostmail.com env(MAILER_PORT): 587 env(MAILER_USER): SMTP_Injection env(MAILER_PASS): env(SECRET): ThisTokenIsNotSoSecretChangeIt short_link_host: %env(SHORT_LINK_HOST)% env(SHORT_LINK_HOST): fallback.local Default values, get overridden if provided in the env How I dealt with libraries that don’t support env vars or values needed in controllers Note the structure around the name
  • 36. doctrine: dbal: url: '%env(DATABASE_URL)%' orm: auto_generate_proxy_classes: '%kernel.debug%' naming_strategy: doctrine.orm.naming_strategy.underscore auto_mapping: true swiftmailer: transport: "smtp" host: "%env(MAILER_HOST)%" port: "%env(MAILER_PORT)%" username: "%env(MAILER_USER)%" password: "%env(MAILER_PASS)%" spool: { type: "memory" } How they’re used - in configuration YAML files...
  • 37. services: amazon_s3: class: AwsS3S3Client arguments: - credentials: key: "%env(AWS_ACCESS_KEY_ID)%" secret: "%env(AWS_ACCESS_SECRET_KEY)%" region: "%env(AWS_REGION)%" version: "2006-03-01" How they’re used - in service configuration files...
  • 38. While you’re porting ● Consider what values actually change between deployment environments ● Anything that doesn’t change, should go into config.yml, config_dev.yml or config_prod.yml (a la current standard edition practice). ● Anything that changes is a good candidate to live in the environment.
  • 39. Any gotchas? ● Need to defer making decisions on anything that changes per-deployment until later. i.e. any decisions made in a container extension. ● Dynamic parameters don’t solve this %param% => %env(PARAM)% ● If it’s your bundle/extension, you can use factory services to work around this.
  • 40. The Dotenv component in 3.3 ● Symfony flex uses it out of the box! ● A small class that is added in your app/app_dev.php and console scripts ● Provides env-var like support in places you can’t easily set variables (dev!) ● In Flex, it replaces the parameters.yml paradigm ● Relatively easy to back-port into the full-stack framework
  • 41. Or…
  • 43. You can use docker in development!
  • 45. It’s not (all) about security.
  • 47. Environment vars are not perfect ● Does not solve security for anyone with access to the machine. ● Can still be accessed from outside your app - i.e. anything in shell_exec() calls. ● The PHP user or someone on CLI can expose to another program. ● Any insecure libraries in your app can access it, too. ● Can unintentionally turn up in logs, the Symfony profiler, etc. ● The plain-text values are probably still stored somewhere.
  • 48. How do I make it better? ● Current PR: github/symfony/symfony#23901 (due 3.4) adds features to support docker/kubernetes secrets & make it extendable. ● Once it’s available to us, it might be like this… ○ on AWS? KMS-encrypted envvars or SSM Param. Store. ○ Not AWS? G-Cloud KMS, or other open-source, e.g. Hashicorp Vault, Pinterest Knox, Lyft Confidant. ● In the meantime: do you host on AWS? Use KMS-encrypted environment variables or fetch from SSM Param. Store at container boot.
  • 49. ● Any of these principles a surprise? Read about 12-factor apps ● Segment have a great write-up on managing secrets on AWS on their blog. ● KMS-ed envvars (enc. strings): REA’s Shush is a tiny go library to help. ● SSM param. store (central management): Segment’s Chamber can help. ● Taking inspo from k8s, Docker swarm mode now has secrets built-in. ● Not using Docker? Can be quite complicated to set env across multiple users + daemons. Apache, and CLI users share a syntax, PHP-FPM is different. ● Example of porting a Symfony app to Docker - for the adventurous. Further reading & tools
  • 50. thank you. stalky stalk: @sammyjarrett or linkedin.com/in/samjarrett more detail and these slides published at samjarrett.com.au/swipe-right

Editor's Notes

  • #5: Since 2.0 beta, before all the current patterns we now use existed, before the documentation was any good. Terrible atrocities: here to atone, really.
  • #7: For PHP apps, booting refers to the app loading on each page load Not just something that occurs in PHP. Ruby, Python, Node, etc all do this. In comparison, Symfony demands that you compile the application before you boot it. We call it building the container. Or clearing the cache. Symfony steals a lot from Java, which also also suffers from the same issue, but you notice it differently... Here’s something I’m sure we’re all familiar with...
  • #8: This is familiar with any time you’ve ever booted a java app. Building the configuration tree and configuring the services is mostly why they take so long to start accepting traffic!
  • #9: Which gives us a good speed improvement because the app doesn’t have to load all of it’s configuration and build the container at runtime! This creates a big problem when we have complex build and deploy processes that need to operate at scale (how do you deploy to 20+ instances quickly? prebuild!) and still protect secret values Modern deployment practices emphasise keeping the artifact static between environments, to be able to more easily replicate issues back in development or testing environments. Container compilation means that we can’t guarantee that our artifact compiles correctly or that it is exactly the same in production. So, how do we solve this in symfony?
  • #10: But this naturally creates issues when we have secrets in our apps, and yep, the modern app has a lot of them
  • #13: What is a secret? Secrets can be any form of data that you wouldn’t want to be widely spread around.
  • #14: Internal hostnames (i.e. unprotected internal systems you’re hiding): redis, memcached, finance systems, etc Lead developer’s email address (for emailing emerging issues, I guess) Pagerduty/OpsGenie alert topics/email address (don’t want these abused overnight waking up on call staff!) Slack tokens Summary: secret is anytthing you wouldn’t want to put in the markup
  • #17: Create a single class or factory class, and delegate responsibility for it to provide you with answers, Ultimately embedding the secret for all environments in it. Compromise here on either test or production means all of your secrets are gone.
  • #18: Use ini, json, yaml, java.properties style or some other configuration format to specify all of your values Create a php-class as a template full of placeholders that a template parser can quickly generate the final value for you Generate the PHP from the template before deploying (as part of a build or deploy process) Include the final configuration (without the config file) as part of your deployment artifact. Profit?
  • #19: Since we’re having an amnesty session, here’s my big professional mistake.
  • #20: Dropping a production database because a test-site was misconfigured to use it by one of the above secret management methods (you can guess) Let’s have some drinks after and I’ll expand on the unprofessional ones.
  • #21: Same management principal as the config class (“know it all”), finally we add some Symfony flair! Use config_dev.yml and config_prod.yml to store secrets for each environment Largely seen in remnants of old Symfony 2.0 projects, from before the framework didn’t suggest a way of swapping values out yet (i.e. pre-parameters.ini) Some apps that have existed since then and just been upgraded still contain bits and pieces of this
  • #24: No disrespect to Fabien. He’s a super smart guy and this works pretty good. But we evolve.
  • #25: Symfony provides such a simple way forward and we all go running to do it! Let’s make everything a parameter! What’s wrong with this?
  • #26: CI systems can be hacked. If it’s in S3 or on a server somewhere that the CI can access, can others? Do you audit access to this?
  • #27: In the midst of a security incident, this may allow an unacceptable delay to roll a pivotal secret, or mean that your application “goes down” or has degraded functionality until the build/deploy completes. If the key is something critical (e.g. database), you can’t do a rolling deploy.
  • #28: Lost your DB creds? You can recover them in var/cache/prod/appProdContainer.php! Great idea until the framework actually gained traction and then become subject to every hacker and their dog knowing how to do this.
  • #29: Want to add a pre-prod? Or test a new feature on prod-like infra? New deployments now involve: updating your CI & build process, building a new artifact, updating your deployment process & tools
  • #30: How sure are you that the issue doesn’t exist solely on production? Can developers drag the exact artifact down to their machine to replicate?
  • #37: Wow this project was inconsistent with config values and quotes
  • #39: In symfony we think of app environments, and try to keep agnostic to deployment environments (test server is still prod app environment), but for this, consider deployment envs.
  • #41: Biggest challenge is dev environments where setting envvars is traditionally hard
  • #46: I’ve talked a bit about security, but it’s not really. And her’es the big gotcha
  • #48: Has the same flaws as any other parameter, plus a few new ones