mirror of
https://github.com/hanzoai/ai.git
synced 2026-11-21 02:36:49 +00:00
GetApplication resolved admin/<app>. GetCert resolved <IAM_ORG>/<cert>. An application's `cert` field is a bare name and the cert row is written owner=admin, so any deployment whose IAM_ORG was not "admin" — which is every real one — read its application fine and then could not find that application's certificate. The store had the cert the whole time. Only the question was addressed to the wrong tenant, and IAM answered it the way it answers any miss: "the entity does not exist". So the failure named a missing certificate rather than a misaddressed lookup, and what actually broke was one step further on — with no cert there is no key to validate a bearer against, so the process cannot authenticate anything. Seen on hanzo-devnet the moment identity moved in-process: /v1/models 503, `read cert "cert-hanzo" for application "hanzo-cloud": the entity does not exist`, while get-cert?id=admin%2Fcert-hanzo returned that same cert with a 200. The partition is now named once — PlatformOwner — and applications, organizations and certs all read through it, so an application and its own certificate can no longer be looked up in two different places. Asserted on the REQUEST URL, not on a response: the defect was never in what IAM returned, it was in which tenant we asked. Mutation-checked — putting GetCert back on c.OrganizationName fails the test. Co-authored-by: Hanzo Dev <[email protected]>
63 lines
2.2 KiB
Go
63 lines
2.2 KiB
Go
// Copyright 2023-2026 Hanzo AI Inc. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package iam
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
// Application is the subset of the IAM Application model ai reads: DisplayName,
|
|
// the signing cert name, and the OAuth redirect allowlist. Read-only response
|
|
// (GetApplication), so a projection is correct.
|
|
type Application struct {
|
|
Owner string `json:"owner"`
|
|
Name string `json:"name"`
|
|
DisplayName string `json:"displayName"`
|
|
Cert string `json:"cert"`
|
|
RedirectUris []string `json:"redirectUris"`
|
|
}
|
|
|
|
// GetApplication fetches an application by name (owned by admin).
|
|
// PlatformOwner is the reserved org that holds cross-tenant configuration:
|
|
// applications, organizations and the signing certs applications point at. It is
|
|
// not a tenant and nothing customer-facing lives in it.
|
|
//
|
|
// It is a constant, and named, because these reads MUST agree. An application
|
|
// addressed in one partition and its certificate in another resolves an app and
|
|
// then fails to resolve the key that app's tokens are signed with — which reads
|
|
// as a missing cert rather than as a mis-addressed one.
|
|
const PlatformOwner = "admin"
|
|
|
|
func (c *Client) GetApplication(name string) (*Application, error) {
|
|
url := c.GetUrl("get-application", map[string]string{
|
|
"id": fmt.Sprintf("%s/%s", PlatformOwner, name),
|
|
})
|
|
bytes, err := c.DoGetBytes(url)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var application *Application
|
|
if err = json.Unmarshal(bytes, &application); err != nil {
|
|
return nil, err
|
|
}
|
|
return application, nil
|
|
}
|
|
|
|
// GetApplication uses the configured (or env-derived) client.
|
|
func GetApplication(name string) (*Application, error) {
|
|
return ensureClient().GetApplication(name)
|
|
}
|