Skip to content

Commit f83097b

Browse files
mitc-gjugeclaude
andcommitted
fix(dns): spell out the OVH right that lists zones
OVH matches access rules per exact path: a `GET /domain/zone/*` rule grants the subtree but not the bare `GET /domain/zone` that listZones and testConnection call. Verified against a live account with a consumer key carrying that single wildcard rule: GET /domain/zone -> 403 This call has not been granted GET /domain/zone/ -> 200 GET /domain/zone/{zone}/record -> 200 The form only asked for rights on `/domain/zone/*`, so a token created by following it could not list zones at all, and the failure surfaced as a bare "This call has not been granted" that points nowhere. The hint now lists the five rights verbatim, and a token missing the root one gets an error that names it instead of echoing OVH's message. Reported by @narcisonunez on Dokploy#5258. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 80a6baf commit f83097b

3 files changed

Lines changed: 49 additions & 8 deletions

File tree

‎apps/dokploy/__test__/dns/ovh.test.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,23 @@ describe("ovhClient.listZones", () => {
149149
]);
150150
});
151151

152-
it("propagates the API error message", async () => {
152+
it("names the missing root right when OVH refuses the zone listing", async () => {
153153
const cfg = freshConfig();
154154
mockApi(ovhError("This call has not been granted", 403));
155155

156+
// A `GET /domain/zone/*` rule does not cover the bare `GET /domain/zone`,
157+
// so the raw OVH message would send users looking in the wrong place.
156158
await expect(ovhClient.listZones(cfg)).rejects.toThrow(
157-
"This call has not been granted",
159+
/missing the `GET \/domain\/zone` right/,
158160
);
159161
});
162+
163+
it("propagates the API error message", async () => {
164+
const cfg = freshConfig();
165+
mockApi(ovhError("Invalid signature", 403));
166+
167+
await expect(ovhClient.listZones(cfg)).rejects.toThrow("Invalid signature");
168+
});
160169
});
161170

162171
describe("ovhClient.listRecords", () => {

‎apps/dokploy/components/dashboard/settings/dns/handle-dns-provider.tsx‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,22 @@ export const HandleDnsProvider = ({ dnsProviderId }: Props) => {
488488
<Input type="password" {...field} />
489489
</FormControl>
490490
<FormDescription>
491-
Create the three keys at once on api.ovh.com/createToken
492-
with the <code>GET</code>, <code>POST</code>,{" "}
493-
<code>PUT</code> and <code>DELETE</code> rights on{" "}
494-
<code>/domain/zone/*</code>.
491+
Create the three keys at once on
492+
api.ovh.com/createToken, with exactly these five rights:
493+
<br />
494+
<code>GET /domain/zone</code>
495+
<br />
496+
<code>GET /domain/zone/*</code>
497+
<br />
498+
<code>POST /domain/zone/*</code>
499+
<br />
500+
<code>PUT /domain/zone/*</code>
501+
<br />
502+
<code>DELETE /domain/zone/*</code>
503+
<br />
504+
The first one lists your zones and has to be granted on
505+
its own: OVH matches rights per exact path, so{" "}
506+
<code>/domain/zone/*</code> does not cover it.
495507
</FormDescription>
496508
<FormMessage />
497509
</FormItem>

‎packages/server/src/utils/dns/ovh.ts‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,29 @@ const recordBody = (
209209
...(record.ttl === undefined ? {} : { ttl: record.ttl }),
210210
});
211211

212+
// OVH grants access per exact path: a `/domain/zone/*` rule covers the subtree
213+
// but not the bare `/domain/zone` listing, which needs its own rule. That is an
214+
// easy one to leave out of a token, so say so plainly rather than surfacing a
215+
// bare "This call has not been granted".
216+
const listZoneNames = async (config: OvhConfig) => {
217+
try {
218+
return await ovhFetch<string[]>(config, "/domain/zone");
219+
} catch (error) {
220+
if (
221+
error instanceof Error &&
222+
error.message.includes("has not been granted")
223+
) {
224+
throw new Error(
225+
"OVH: the credentials are missing the `GET /domain/zone` right, which lists your zones. A `GET /domain/zone/*` rule does not cover it — add the rule without the wildcard as well.",
226+
);
227+
}
228+
throw error;
229+
}
230+
};
231+
212232
export const ovhClient: DnsClient<OvhConfig> = {
213233
async listZones(config) {
214-
const zones = await ovhFetch<string[]>(config, "/domain/zone");
234+
const zones = await listZoneNames(config);
215235
return zones.map((zone) => ({ id: zone, name: zone }));
216236
},
217237

@@ -318,6 +338,6 @@ export const ovhClient: DnsClient<OvhConfig> = {
318338
},
319339

320340
async testConnection(config) {
321-
await ovhFetch(config, "/domain/zone");
341+
await listZoneNames(config);
322342
},
323343
};

0 commit comments

Comments
 (0)