TRANSKRIPTIO 🔗
WEBVTT
00:00:04.559 --> 00:00:07.919
Most applications have to deal with secret information.
00:00:08.160 --> 00:00:14.640
From API keys to passwords to connection strings, connecting to sensitive resources involves secrets.
00:00:14.880 --> 00:00:16.000
So where do you put them?
00:00:16.160 --> 00:00:18.640
How do you ensure they are staying secret?
00:00:18.879 --> 00:00:28.320
Those answers change based upon a lot of factors, including development versus production, and whether or not you're using an AI to help you in development.
00:00:28.640 --> 00:00:31.920
So let's talk about it in today's episode of DevQuestions.
00:00:41.200 --> 00:00:43.920
Software development is more than just writing code.
00:00:44.159 --> 00:00:45.600
So let's talk about the rest of it.
00:00:45.759 --> 00:00:50.000
Specifically, let's talk about where to store your secrets as a developer.
00:00:50.240 --> 00:00:56.320
And let's start off by saying that this answer has changed a bit in light of AI agents.
00:00:56.479 --> 00:01:00.880
So what was recommended practice isn't necessarily the right call anymore.
00:01:01.039 --> 00:01:04.239
Also, I'm going to be addressing this as a.NET developer.
00:01:04.480 --> 00:01:07.519
If you are a.NET developer, some of this might not apply.
00:01:07.680 --> 00:01:09.120
However, most of it will.
00:01:09.200 --> 00:01:11.760
And the principles will be similar for your language.
00:01:11.920 --> 00:01:15.200
I will be talking about front-end frameworks like React as well.
00:01:15.519 --> 00:01:17.439
So that will directly apply.
00:01:17.680 --> 00:01:19.200
Let's start with a big one.
00:01:19.439 --> 00:01:24.079
Developers should not have access to any production resources.
00:01:24.480 --> 00:01:32.239
Now, there is an exception here for if you're on a very small team where you're also the production deployment person.
00:01:32.560 --> 00:01:36.159
But even then, there needs to be some separation.
00:01:36.719 --> 00:01:51.200
So the information you have, whether you are a small team as your job too, or whether it's somebody else's job, the information about the secrets, about the connection strings, and other things should be stored in something like Azure Key Vault.
00:01:51.519 --> 00:01:57.359
And the devs should not have access to it or to the production servers.
00:01:58.079 --> 00:02:04.239
This is especially true if AI has access to developer machines.
00:02:06.079 --> 00:02:08.240
AI looks for credentials.
00:02:08.319 --> 00:02:13.840
It's unfortunately one of the things that people don't realize AI does.
00:02:14.240 --> 00:02:21.120
When you give an AI permission to look at your hard drive, it doesn't always stay where it's supposed to stay.
00:02:21.280 --> 00:02:23.120
Sometimes it wanders a bit.
00:02:23.280 --> 00:02:36.960
And one of the things that we have seen over and over is that an AI will look to elevate its own permissions to solve the problem of not having access to something.
00:02:37.439 --> 00:02:49.280
And it has more than one once looked and found those credentials and then treated that like it's a development resource and done some pretty horrific things in production.
00:02:49.759 --> 00:03:02.319
So we need to be very careful to separate out our sensitive data from our AIs, but even from developers, they should not have access to production.
00:03:02.560 --> 00:03:05.439
And I know a lot of developers say, no, I definitely should.
00:03:05.520 --> 00:03:06.800
How else could I debug it?
00:03:06.960 --> 00:03:07.919
How else could I?
00:03:08.080 --> 00:03:12.879
There are ways, as long as you're focused on being secure.
00:03:13.520 --> 00:03:22.800
If you're focused on being fast and on just quote unquote getting the job done and not worried about security, sure.
00:03:23.120 --> 00:03:28.400
Have access to the keys for everything and then just be safe, right?
00:03:28.560 --> 00:03:31.039
But that's not a good practice.
00:03:31.360 --> 00:03:38.159
A good practice is to have clear separation and automated systems that take you the last steps.
00:03:38.560 --> 00:03:49.280
Because part of your process should be a good CI CD process that takes your code from one location to another in automated manner.
00:03:49.360 --> 00:03:53.039
So you're testing how it's going to work when you deploy.
00:03:53.360 --> 00:03:59.919
That way you are sure this is going to work and you're not going to have surprises when you hit production.
00:04:00.080 --> 00:04:06.879
This makes your deployment to production faster, it makes it cleaner, it makes it less likely to have to be rolled back and more.
00:04:07.280 --> 00:04:10.879
So that whole process should be automated anyway.
00:04:11.120 --> 00:04:16.959
So developers shouldn't be touching production directly for deployments.
00:04:17.279 --> 00:04:22.079
So the other part of that is well, developers need to have access in order to debug stuff.
00:04:22.319 --> 00:04:39.279
Well, if you are properly backing up your production systems, especially your databases, and then cleaning that data and putting it into development as a development database, you often don't need to even do that because the development data is just hours different than production.
00:04:39.600 --> 00:04:44.639
So all of a sudden, now you have all the data you need while being secure.
00:04:44.800 --> 00:04:59.040
Things like email addresses have been sanitized, things like person-identifiable information has been changed so that you're not giving developers access to sensitive information, but at the same time, they have all the information they need for testing.
00:04:59.279 --> 00:05:06.959
And your environment should be very, very similar between production and development so that you can accurately test on things.
00:05:07.279 --> 00:05:20.879
So, yes, I recommend that developers not have access to any production resources, especially not just because, but especially if they use AI.
00:05:21.360 --> 00:05:29.199
Load full transcript
Because too often AI will use those credentials or ingest those credentials, which means they all need to be rotated.
00:05:29.839 --> 00:05:33.759
Okay, so what do you do during development?
00:05:34.079 --> 00:05:41.120
Well, if you're a.NET developer, store your secrets in the user secrets JSON file.
00:05:41.279 --> 00:05:43.680
If you don't know what that is, I've got videos on my channel.
00:05:43.759 --> 00:05:48.480
I have a whole course dedicated to app settings, including user secrets.
00:05:48.639 --> 00:05:51.920
Um, these are for things where it's gonna be local.
00:05:52.240 --> 00:06:04.000
So you're working on a local database, you're working on a local email server equivalent where it's just you know showing that yes, an email went out or something like that, but it's not actually sending emails.
00:06:04.160 --> 00:06:08.319
Um, all these different things, they're local and you have your own local settings.
00:06:08.480 --> 00:06:23.040
If you put those in user secrets, they don't go into your source control, they don't disrupt the other users on the team and what their local secrets are, and yet you can all use your own local secrets to have your own local setup.
00:06:23.199 --> 00:06:24.879
This is the way you do it.
00:06:25.120 --> 00:06:26.639
So that's kind of step one.
00:06:26.800 --> 00:06:28.639
Have a place for local secrets.
00:06:28.800 --> 00:06:30.720
Again,.NET developers, we have it easy.
00:06:30.879 --> 00:06:32.720
We just use user secrets.
00:06:33.040 --> 00:06:38.399
Now, with that, do not give AI access to your hard drive.
00:06:38.639 --> 00:06:40.800
Which you probably say, uh, that's too late for that.
00:06:40.879 --> 00:06:41.920
I've already done that.
00:06:42.160 --> 00:06:43.040
Change that.
00:06:43.199 --> 00:06:44.399
Don't do that.
00:06:44.800 --> 00:06:47.680
Instead, run it in a container.
00:06:47.920 --> 00:06:53.360
Give it full access if you want to that container, but not to your actual hard drive.
00:06:53.600 --> 00:06:58.720
Otherwise, there are too many things that AI can do to compromise you.
00:06:58.959 --> 00:07:06.639
It can read through your entire drive and figure out what secrets might be there.
00:07:06.879 --> 00:07:15.759
It can look at different your browser headless and look at all the local storage and session storage in your browser for any secrets that may be there.
00:07:16.000 --> 00:07:22.000
So it can do a lot of things that you really don't want to have at have it have access to.
00:07:22.240 --> 00:07:27.199
And all of a sudden, your AI might have access to things that you never expected it to.
00:07:27.439 --> 00:07:32.480
So make sure you isolate your AI from your actual development machine.
00:07:32.639 --> 00:07:33.759
Run it in a container.
00:07:33.839 --> 00:07:35.199
It's absolutely possible.
00:07:35.279 --> 00:07:36.639
It's not that hard.
00:07:36.879 --> 00:07:38.160
You can do this.
00:07:38.560 --> 00:07:40.879
Make sure you separate it from your development machine.
00:07:40.959 --> 00:07:47.920
Again, because when you store your user secrets in that secrets.json, well, your AI can go and read those.
00:07:48.240 --> 00:07:50.720
And those should not be secret.
00:07:51.040 --> 00:07:51.360
Okay?
00:07:51.839 --> 00:07:53.920
Those should not be a big deal.
00:07:54.079 --> 00:07:57.120
They should be something that can be given away.
00:07:57.279 --> 00:08:03.360
They because you should be using like, you know, SA for both a username and password for a SQL database.
00:08:03.439 --> 00:08:09.199
And you might, you know, using a connection string that has no credentials but lets you log into a local database.
00:08:09.439 --> 00:08:12.160
These things should not be secrets.
00:08:12.399 --> 00:08:21.360
But you still don't want to have access, give AI access to things it shouldn't have access to, especially if you're a person who reuses credentials too much.
00:08:21.519 --> 00:08:22.560
Don't do that.
00:08:23.120 --> 00:08:25.199
And that kind of leads us into the next point.
00:08:25.519 --> 00:08:29.120
Do not access production resources locally.
00:08:29.759 --> 00:08:35.279
This is one that we all violate at some point because it's just easier.
00:08:35.600 --> 00:08:38.159
And don't do this, don't give into this.
00:08:38.320 --> 00:08:45.600
But this is one where, you know what, I'm gonna put the production connection string in my app and run it locally just to see what's happening.
00:08:45.759 --> 00:08:51.519
But I can debug easier if I have Visual Studio open in debug mode, but have the production connection string.
00:08:51.759 --> 00:08:52.879
Don't do that.
00:08:53.120 --> 00:08:58.000
Because then what happens is you've given access to potentially an AI to scan that.
00:08:58.240 --> 00:09:04.240
If you have, if you're using Visual Studio, you might have copilot running and that could potentially see your connection strings.
00:09:04.480 --> 00:09:05.279
Don't do that.
00:09:05.519 --> 00:09:09.840
You might accidentally put it into source control, and that's a big issue.
00:09:10.000 --> 00:09:12.080
Um so don't do that.
00:09:12.320 --> 00:09:15.679
Don't use production resources locally.
00:09:15.759 --> 00:09:19.840
It's just too easy to let those slip out in some way.
00:09:20.720 --> 00:09:25.919
Next up, do not give AI full access to GitHub.
00:09:26.159 --> 00:09:30.000
Again, I've told you put AI in a container and run a container.
00:09:30.240 --> 00:09:33.759
Well, give it a personal access token.
00:09:33.919 --> 00:09:34.240
Okay.
00:09:34.480 --> 00:09:39.440
Don't give it a full token, give it access to just what it needs in GitHub.
00:09:39.600 --> 00:09:52.080
Because again, if you give it full access, if you get your access to GitHub, if it's using your access on your machine, well, you have access to go look at user secrets potentially or change user secrets.
00:09:52.320 --> 00:09:53.440
That's a problem.
00:09:53.679 --> 00:09:59.360
Like there are GitHub secrets that it could access or use in a way that you don't want it to use.
00:09:59.600 --> 00:10:00.639
Don't do that.
00:10:00.799 --> 00:10:03.600
Don't give it full access to GitHub.
00:10:03.840 --> 00:10:07.360
Use a personal access token and limit that, restrict that.
00:10:07.600 --> 00:10:13.840
Next up, use containers for all local development resources as much as possible.
00:10:14.080 --> 00:10:18.240
So for instance, I used to install SQL Server on my development machine.
00:10:18.320 --> 00:10:21.279
I use it so often, I'm like, well, this is what you do.
00:10:21.360 --> 00:10:24.559
You install it locally because I don't want to work across a network somehow.
00:10:24.720 --> 00:10:30.159
And yes, you can use local DB or something like that, but it was just easy to install SQL Server.
00:10:30.240 --> 00:10:33.519
I haven't done that in years because I use containers.
00:10:33.759 --> 00:10:37.120
I can spin up a SQL Server in minutes and have it running.
00:10:37.279 --> 00:10:47.679
I have a SQL Server, I have a MongoDB server, I have a RavenDB server, I have uh Azure, I have a whole bunch of different servers running when I need them to.
00:10:47.759 --> 00:10:50.159
And when I don't need them to, I shut them down.
00:10:50.639 --> 00:10:51.840
This isolates them.
00:10:51.919 --> 00:10:55.200
It also makes them very easy to dispose and restart.
00:10:55.919 --> 00:10:57.279
This is something you want to do.
00:10:57.440 --> 00:11:04.559
Get used to using containers, use them over and over again, but then throw them away when you don't need them anymore and start over.
00:11:05.120 --> 00:11:06.960
Containers are amazing.
00:11:07.120 --> 00:11:14.799
They make your system run faster, but you're not running SQL Server in the background, taking up lots of memory for no reason.
00:11:15.039 --> 00:11:20.720
So it makes your system faster, but it also makes it easier to reset things and start over.
00:11:20.960 --> 00:11:26.879
So as a developer, you shouldn't be directly accessing production systems or resources.
00:11:27.039 --> 00:11:28.480
Keep that separation clear.
00:11:28.720 --> 00:11:33.360
Otherwise, a mistake locally can damage or destroy your production systems.
00:11:33.519 --> 00:11:37.679
Instead, use local resources with throwaway credentials for local development.
00:11:37.919 --> 00:11:42.720
Even then, keep your AI tools and agents away from your development machine itself.
00:11:42.879 --> 00:11:50.960
Keep them segmented into containers or virtual machines so they cannot find elevated permissions in a credential hunt.
00:11:51.519 --> 00:11:55.039
They're gonna try at some point, just protect yourself.
00:11:55.200 --> 00:11:55.519
All right.
00:11:55.679 --> 00:11:56.559
Thanks for listening.
00:11:56.799 --> 00:11:58.559
As always, I am Tim Corey.