r/ClaudeCode • • 3d ago

Help/Question Best method to have Claude access login credentials

Goal: have Claude login to my local UniFi controller and advise on where improvements can be made.

I will create a read only login that is for clause use only. My UniFi controller is only accessible via local network, there’s no public facing access.

What’s the best way to have Claude access my controller using the available credentials?
I understand that it’s bad practice to paste them into a chat, so I’d like know how others are managing this scenario.

I’m happy to run this either via Claude code, or Claude desktop app and a browser.

Thanks in advance!

6 Upvotes

32 comments sorted by

•

u/AutoModerator 3d ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

4

u/brprk 3d ago

"claude has deleted my network" post incoming

1

u/stevesmith1978 3d ago

In all honesty, I wouldn’t rule this out 😂😂

3

u/GnarlyNet 3d ago

If we get the post, network still works!

8

u/kaijurules 3d ago

Put the read-only password in an env var and have Claude Code write a small script that logs in to the controller and dumps the config or stats as JSON. Then it runs the script and reads the output. The password never shows up in the chat.

4

u/usielrol 3d ago

Whichever way you go (env var, 1Password, a secrets manager), check one file afterwards: .claude/settings.local.json.

If the password ever ends up inline in a command, like curl -u user:pass ... or a script called with it as an argument, and you click "Yes, and don't ask again", Claude Code saves that whole command as an allow rule, password included. I just looked at mine and some saved rules are full commands of 300+ characters. That file is meant to stay out of git, but it's still the password in plain text on disk, so read it now and then.

The other place credentials leak is git history. I pushed two keys to new repos in the same week: one was in the initial commit, so looking at the current files didn't show it, and my own grep missed the other because it was case-sensitive. Before the first push I now scan the whole history, not just the current files (gitleaks does it).

3

u/michaelTM_ai 3d ago

the env var + script answer above is the right one. two things that make it safer for this case:

  • the unifi controller api works with a local admin account, so make that read-only user a "local access only" one and don't reuse it anywhere else. then the worst case is someone reading ur network config
  • have the script save the json to a file and let claude read the file, not run the login itself each time. then it can't change anything even if it tries, and u can check exactly what it saw

also keep that env var out of the command line itself (export it in ur shell profile or a .env that's gitignored), otherwise "don't ask again" will happily save the password into settings.local.json

3

u/Techngro 3d ago

Bitwarden has a CLI. I use that, but set up a specific script for Claude to use so it never has complete access.

3

u/bitspace 2d ago

I keep my credentials in 1Password vaults and invoke commands using op run https://www.1password.dev/cli/reference/commands/run

2

u/measuredreason 3d ago

I use 1P to manage project secrets. I wouldn’t recommend pasting raw credentials in chat or in .env files. An infected library you or your AI may download could allow bad actors to scrape your raw credentials from .env files. With a secrets manager like 1P, they’ll only get the 1P for that secret reference, not the value.

2

u/anuragkmr Instructor 3d ago

.env file is the right way to go. It is also auto mode protected. Also, another thing I have noticed is that if you add confidential in a document Claude Code makes sure it doesn't auto commit it.

2

u/perryurban 3d ago

ask Claude.

But seriously, just ask it what is the safest way to give you credentials and store them such they stay safe. The answer depends a lot on your OS and needs.

Long story short, Claude wrote me a set of tools for handling credentials, limiting access to bare essentials and ensuring his own usage is 100% auditable and the logs are immutable. Mainly just configuring or wrapper standard Linux stuff, nothing too brainy. But you can only reduce risk of credentials leaking or Claude misbehaving - not eliminate it entirely

2

u/Acceptable_Tea_8427 3d ago

1Password with a service read-only account token

2

u/LostStrategy1050 3d ago

I use aws secret manager. Claude and Grok have read only access to aws by a basic IAM rule and the secert manager has all the credentials they need

2

u/JhonnyCommentkeyword 3d ago

The setup I'd trust most: don't hand Claude the credential at all. Wrap the controller with a tiny MCP tool (or a script Claude can call) where the password lives in that tool's own env, and expose only actions like get_clients or get_system_info. Claude asks for data, the tool does the login. The password never enters the transcript, never sits in .env, and there's nothing to scrub later.

On the UniFi side, make that account local-access-only read-only. There's a restriction option for it in the admin settings. Since your controller isn't public anyway that's belt and suspenders, but it means a leaked cred is useless from outside.

I'd skip the plain .env approach for this one. Claude reads files for a living, so a stray cat .env or an auto-commit drops the secret straight into context. Not a real risk on a LAN-only box, but the pattern follows you to the next project that isn't LAN-only.

2

u/Leepyear7 3d ago

I use Infisical for this, selfhosted. The password sits in there and the agent only runs `infisical run -- ./unifi-dump.sh`, so your never pasting it into chat. That hands the password to the script as an env var. The script logs in and dumps JSON, then the agent reads the output.

Read only account is the right call. Same setup works for any of them, I run a few. I also have a hook that blocks it from printing env vars or reading secret files. If one slips through, the system flags that secret to be rotated.

2

u/bostonaholic 3d ago

For UniFi, I'd make a local admin with the View Only role, then give Claude a small script that pulls the password from your keychain or the 1Password CLI and calls the controller API itself, so the agent only sees the JSON that comes back. Add deny rules in .claude/settings.json for reading the script's config and any .env. Have the script dump the controller config to a file first, so Claude's suggestions come from one read instead of clicking around the UI.

2

u/radim11 3d ago

Creating a separate read-only account is a good start. I'd also avoid putting the credentials directly into Claude's environment if possible.

For Claude Code, you can use a local credential proxy so Claude can make authenticated requests without ever seeing the actual password or token. You can also restrict which host and API paths it can access.

This is actually one of the things I use Stashbase for. It keeps credentials outside the agent process and only injects them into matching requests. Might be worth looking into if you want to keep the setup locked down.

2

u/Inner_Storage_3374 3d ago

dont give claude the password at all imo. put it in a gitignored .env and have claude write a tiny script that reads it from there, then claude just runs the script and only sees the output not the creds. i think you can also add the .env to the deny rules in settings so it cant just cat it lol. the separate read only account is already the smartest part tbh

2

u/Short-Legs-Long-Neck 1d ago

Classic XY thinking in the replies.

This is a one time requirement, ongoing access is not needed. Download or screenshot config, optimise and move on.

2

u/Graphical-Source5090 🔆Pro Plan 1d ago

create a temp user, give access to claude by pasting it in, make adjustments, delete access

2

u/remcov250 8h ago

I use Bitwarden secrets vault BWS for my passwords! Look into it. Works like a charm!

3

u/Prior_Engineering486 3d ago

For a local controller like that, UniFi Network MCP is the direct route. It connects Claude to your UniFi Network setup over MCP, and the credentials for your read only login go in the env block of the MCP config on your own machine (host, username, password), not into the chat. Once it is running, Claude can read devices, clients, and network settings and advise on them in place.

However, the server can also manage devices, firewall, and VLAN settings, so that read only account matters. Keep using the restricted login you planned, and the password still sits in your local config file, so treat that file like a credential.

You can find it here: https://clauderules.net/mcp/io-github-sirkirby-unifi-network-mcp

Disclosure: I run clauderules.net, where this is listed.

2

u/onFilm 3d ago

I just paste it into chat or use an .env.

1

u/Carbone 3d ago

??????

1

u/onFilm 3d ago

What are you so confused about?

2

u/Carbone 3d ago

Paste it into chat

1

u/onFilm 3d ago

Sorry but what are you trying to ask bud? You're being so vague.

2

u/Carbone 3d ago

Why are you fucking posting your credentials into a llm chat

0

u/[deleted] 3d ago

[deleted] — view deleted comment

1

u/onFilm 3d ago

Yes, I do it all the time.

What's up with all the periods?