Commit 051691f
committed
fix(mcp): resolve the auth token per request so rotation needs no restart
Backport of dba-agent 5d7ffc3 (mcp/ portion only).
The MCP server is a long-lived stdio subprocess that snapshotted
DEEPSQL_AUTH_TOKEN once at spawn into an immutable config. Where a provisioner
rotates the token on disk without respawning the process, the captured token
eventually expires, every tool call silently 401s, and re-provisioning is ignored
by the dead process — a restart being the only remediation.
The bearer token is now resolved per request from DEEPSQL_TOKEN_FILE, cached by
mtime so disk is touched only when the file actually changes, with a single
re-read-and-retry on 401 when the token has since rotated. 403 is never retried
(RBAC denial, not stale creds), and installs with no token file keep using the
env snapshot, so editor and CLI behaviour is unchanged.
Scope note: the commit's hermes/deploy/provisioner.py and provision-profile.sh
changes are deliberately NOT ported — this distribution does not ship the
containerised agent. Nothing here writes DEEPSQL_TOKEN_FILE, and setup-agent.sh
mints a token with no expiry (POST /auth/mcp-tokens with no expiresAt), so the
rotation path is currently inert for self-host. It is ported for parity and for
anyone running their own provisioner; the env-snapshot fallback means it costs
nothing when unused.
Also documents why agent.provisioner-url defaults to a deepsql-agent container
that this stack does not run: provisioning is gated on agent.provision-secret,
which is unset by default, so the unreachable URL is never contacted and
setup-agent.sh writes the u-<user> profile locally instead. Behaviour unchanged;
the default value is untouched.
Tests: 259/259 (up from 252 — 7 ported cases covering token-file reads, the mtime
cache, the 401 retry, 403 not retrying, and createConfigFromEnv wiring).1 parent ddbea0b commit 051691f
3 files changed
Lines changed: 269 additions & 26 deletions
File tree
- backend/src/main/java/com/dbaagent/service
- mcp
Lines changed: 15 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
65 | 79 | | |
66 | 80 | | |
67 | 81 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
| |||
1038 | 1040 | | |
1039 | 1041 | | |
1040 | 1042 | | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
1041 | 1088 | | |
1042 | 1089 | | |
1043 | 1090 | | |
1044 | 1091 | | |
1045 | 1092 | | |
1046 | 1093 | | |
1047 | | - | |
1048 | | - | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
1049 | 1097 | | |
1050 | 1098 | | |
1051 | 1099 | | |
| |||
1070 | 1118 | | |
1071 | 1119 | | |
1072 | 1120 | | |
1073 | | - | |
| 1121 | + | |
1074 | 1122 | | |
1075 | 1123 | | |
1076 | 1124 | | |
1077 | 1125 | | |
1078 | 1126 | | |
1079 | | - | |
| 1127 | + | |
1080 | 1128 | | |
1081 | 1129 | | |
1082 | 1130 | | |
| |||
1090 | 1138 | | |
1091 | 1139 | | |
1092 | 1140 | | |
1093 | | - | |
1094 | | - | |
1095 | | - | |
1096 | | - | |
1097 | | - | |
1098 | | - | |
1099 | | - | |
1100 | | - | |
1101 | | - | |
1102 | | - | |
1103 | | - | |
1104 | | - | |
1105 | | - | |
1106 | | - | |
1107 | | - | |
1108 | | - | |
1109 | | - | |
1110 | | - | |
1111 | | - | |
1112 | | - | |
1113 | 1141 | | |
1114 | 1142 | | |
1115 | 1143 | | |
| |||
1124 | 1152 | | |
1125 | 1153 | | |
1126 | 1154 | | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
1127 | 1193 | | |
1128 | 1194 | | |
1129 | 1195 | | |
| |||
1677 | 1743 | | |
1678 | 1744 | | |
1679 | 1745 | | |
1680 | | - | |
| 1746 | + | |
1681 | 1747 | | |
1682 | 1748 | | |
1683 | 1749 | | |
| |||
2273 | 2339 | | |
2274 | 2340 | | |
2275 | 2341 | | |
| 2342 | + | |
| 2343 | + | |
| 2344 | + | |
| 2345 | + | |
2276 | 2346 | | |
2277 | 2347 | | |
2278 | 2348 | | |
| |||
2296 | 2366 | | |
2297 | 2367 | | |
2298 | 2368 | | |
| 2369 | + | |
2299 | 2370 | | |
| 2371 | + | |
2300 | 2372 | | |
2301 | 2373 | | |
2302 | 2374 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
3 | 6 | | |
4 | 7 | | |
5 | 8 | | |
| |||
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
13 | 20 | | |
14 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
15 | 57 | | |
16 | 58 | | |
17 | 59 | | |
| |||
870 | 912 | | |
871 | 913 | | |
872 | 914 | | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
0 commit comments