fix(TALE-29): remove all old ACL_FILE handling

No longer required if the minimum is beta2
This commit is contained in:
Aarnav Tale 2024-08-23 16:12:46 -04:00
parent d041a62fcd
commit 9801ef453d
No known key found for this signature in database
2 changed files with 17 additions and 64 deletions

View File

@ -12,7 +12,7 @@ import Notice from '~/components/Notice'
import Spinner from '~/components/Spinner' import Spinner from '~/components/Spinner'
import { toast } from '~/components/Toaster' import { toast } from '~/components/Toaster'
import { cn } from '~/utils/cn' import { cn } from '~/utils/cn'
import { loadAcl, loadContext, patchAcl } from '~/utils/config/headplane' import { loadContext } from '~/utils/config/headplane'
import { HeadscaleError, pull, put } from '~/utils/headscale' import { HeadscaleError, pull, put } from '~/utils/headscale'
import { getSession } from '~/utils/sessions' import { getSession } from '~/utils/sessions'
@ -27,7 +27,6 @@ export async function loader({ request }: LoaderFunctionArgs) {
session.get('hsApiKey')!, session.get('hsApiKey')!,
) )
console.log(policy)
try { try {
// We have read access, now do we have write access? // We have read access, now do we have write access?
// Attempt to set the policy to what we just got // Attempt to set the policy to what we just got
@ -37,7 +36,6 @@ export async function loader({ request }: LoaderFunctionArgs) {
return { return {
hasAclWrite: true, hasAclWrite: true,
isPolicyApi: true,
currentAcl: policy, currentAcl: policy,
aclType: 'json', aclType: 'json',
} as const } as const
@ -49,35 +47,15 @@ export async function loader({ request }: LoaderFunctionArgs) {
if (error.status === 500) { if (error.status === 500) {
return { return {
hasAclWrite: false, hasAclWrite: false,
isPolicyApi: true,
currentAcl: policy, currentAcl: policy,
aclType: 'json', aclType: 'json',
} as const } as const
} }
} }
} catch (error) { } catch {}
// Propagate our errors through normal error handling
if (!(error instanceof HeadscaleError)) {
throw error
}
// Not on 0.23-beta1 or later
if (error.status === 404) {
const { data, type, read, write } = await loadAcl()
return {
hasAclWrite: write,
isPolicyApi: false,
currentAcl: read ? data : '',
aclType: type,
}
}
throw error
}
return { return {
hasAclWrite: true, hasAclWrite: true,
isPolicyApi: true,
currentAcl: '', currentAcl: '',
aclType: 'json', aclType: 'json',
} as const } as const
@ -91,11 +69,10 @@ export async function action({ request }: ActionFunctionArgs) {
}) })
} }
const data = await request.json() as { acl: string, api: boolean } const { acl } = await request.json() as { acl: string, api: boolean }
if (data.api) {
try { try {
await put('v1/policy', session.get('hsApiKey')!, { await put('v1/policy', session.get('hsApiKey')!, {
policy: data.acl, policy: acl,
}) })
return json({ success: true }) return json({ success: true })
@ -104,16 +81,6 @@ export async function action({ request }: ActionFunctionArgs) {
status: error instanceof HeadscaleError ? error.status : 500, status: error instanceof HeadscaleError ? error.status : 500,
}) })
} }
}
const context = await loadContext()
if (!context.acl.write) {
return json({ success: false }, {
status: 403,
})
}
await patchAcl(data.acl)
if (context.integration?.onAclChange) { if (context.integration?.onAclChange) {
await context.integration.onAclChange(context.integration.context) await context.integration.onAclChange(context.integration.context)
@ -225,8 +192,6 @@ export default function Page() {
? undefined ? undefined
: ( : (
<div className="mb-4"> <div className="mb-4">
{data.isPolicyApi
? (
<Notice className="w-fit"> <Notice className="w-fit">
The ACL policy is read-only. You can view the current policy The ACL policy is read-only. You can view the current policy
but you cannot make changes to it. but you cannot make changes to it.
@ -234,16 +199,6 @@ export default function Page() {
To resolve this, you need to set the ACL policy mode to To resolve this, you need to set the ACL policy mode to
database in your Headscale configuration. database in your Headscale configuration.
</Notice> </Notice>
)
: (
<Notice className="w-fit">
The ACL policy is read-only. You can view the current policy
but you cannot make changes to it.
<br />
To resolve this, you need to configure a Headplane integration
or make the ACL_FILE environment variable available.
</Notice>
)}
</div> </div>
)} )}
@ -357,7 +312,6 @@ export default function Page() {
setToasted(false) setToasted(false)
fetcher.submit({ fetcher.submit({
acl, acl,
api: data.isPolicyApi,
}, { }, {
method: 'PATCH', method: 'PATCH',
encType: 'application/json', encType: 'application/json',

View File

@ -45,7 +45,6 @@ const HeadscaleConfig = z.object({
disable_check_updates: goBool.default(false), disable_check_updates: goBool.default(false),
ephemeral_node_inactivity_timeout: goDuration.default('120s'), ephemeral_node_inactivity_timeout: goDuration.default('120s'),
randomize_client_port: goBool.default(false), randomize_client_port: goBool.default(false),
acl_policy_path: z.string().optional(),
acme_email: z.string().optional(), acme_email: z.string().optional(),
acme_url: z.string().optional(), acme_url: z.string().optional(),