-
Notifications
You must be signed in to change notification settings - Fork 4
feat: migrate OIDC to AGPLv3 #253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
819ce1c
fecf81e
50dd931
93c7926
9fb31f3
2432e26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,8 +17,10 @@ | |
| package com.moneat.events.routes | ||
|
|
||
| import com.moneat.auth.routes.accountDeletionRoutes | ||
| import com.moneat.auth.services.Quadruple | ||
| import com.moneat.billing.routes.billingRoutes | ||
| import com.moneat.billing.routes.publicBillingRoutes | ||
| import com.moneat.billing.services.PricingTierService | ||
| import com.moneat.events.models.AddTargetRequest | ||
| import com.moneat.events.models.AlertNotificationPreferencesResponse | ||
| import com.moneat.events.models.CreateProjectRequest | ||
|
|
@@ -94,6 +96,24 @@ fun Route.apiRoutes() { | |
| // Protected billing routes | ||
| billingRoutes() | ||
|
|
||
| // Subscription tier (for SSO visibility, etc.) | ||
| get("/subscription") { | ||
| val principal = call.principal<JWTPrincipal>() | ||
| val userId = principal!!.payload.getClaim("userId").asInt() | ||
| val pricingTierService = koin.get<PricingTierService>() | ||
| val orgId = | ||
| pricingTierService.getPrimaryOrganizationIdForUser(userId) ?: run { | ||
| call.respond(HttpStatusCode.NotFound, ErrorResponse("No organization access")) | ||
| return@get | ||
| } | ||
| val context = pricingTierService.getEffectiveTierForOrganization(orgId) | ||
|
Comment on lines
+104
to
+109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scope This endpoint is used for tier-gated SSO UI, but 🔧 Suggested fix get("/subscription") {
val principal = call.principal<JWTPrincipal>()
val userId = principal!!.payload.getClaim("userId").asInt()
+ val orgIdClaim = principal.payload.getClaim("orgId").asInt()
val pricingTierService = koin.get<PricingTierService>()
val orgId =
- pricingTierService.getPrimaryOrganizationIdForUser(userId) ?: run {
+ orgIdClaim ?: pricingTierService.getPrimaryOrganizationIdForUser(userId) ?: run {
call.respond(HttpStatusCode.NotFound, ErrorResponse("No organization access"))
return@get
}🤖 Prompt for AI Agents |
||
| call.respond( | ||
| mapOf( | ||
| "tier" to mapOf("tierName" to context.tier.tierName) | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| // Integrations | ||
| integrationRoutes() | ||
|
|
||
|
|
@@ -103,11 +123,11 @@ fun Route.apiRoutes() { | |
| val userId = principal!!.payload.getClaim("userId").asInt() | ||
| val demoEpochMs = call.getDemoEpochMs() | ||
|
|
||
| val (user, orgSlug, sidebarHiddenItems) = | ||
| val (user, orgSlug, orgRole, sidebarHiddenItems) = | ||
| transaction { | ||
| val userRow = | ||
| Users.selectAll().where { Users.id eq userId }.firstOrNull() | ||
| ?: return@transaction Triple(null, null, emptyList()) | ||
| ?: return@transaction Quadruple(null, null, null, emptyList()) | ||
|
|
||
| val membership = | ||
| Memberships | ||
|
|
@@ -124,9 +144,10 @@ fun Route.apiRoutes() { | |
| ?.get(Organizations.slug) | ||
| } | ||
|
|
||
| val role = membership?.get(Memberships.role) | ||
| val hiddenItems = membership?.get(Memberships.sidebar_hidden_items) ?: emptyList() | ||
|
|
||
| Triple(userRow, slug, hiddenItems) | ||
| Quadruple(userRow, slug, role, hiddenItems) | ||
| } | ||
|
|
||
| if (user == null) { | ||
|
|
@@ -141,6 +162,7 @@ fun Route.apiRoutes() { | |
| user[Users.onboarding_completed], | ||
| user[Users.is_admin], | ||
| orgSlug, | ||
| orgRole, | ||
| demoEpochMs, | ||
| sidebarHiddenItems, | ||
| user[Users.phone_number], | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Moneat - observability platform | ||
| // Copyright (C) 2026 Moneat | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Affero General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Affero General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| package com.moneat.sso | ||
|
|
||
| /** | ||
| * Thrown when the caller is authenticated but not permitted to configure SSO | ||
| * (e.g. not an organization owner, or licensing / plan constraints). | ||
| */ | ||
| class SsoForbiddenException( | ||
| message: String, | ||
| ) : RuntimeException(message) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Moneat - observability platform | ||
| // Copyright (C) 2026 Moneat | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Affero General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Affero General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| package com.moneat.sso | ||
|
|
||
| import com.moneat.enterprise.EnterpriseModule | ||
| import com.moneat.sso.routes.ssoRoutes | ||
| import io.ktor.server.application.Application | ||
| import io.ktor.server.routing.Route | ||
|
|
||
| /** | ||
| * Core SSO module providing OIDC single sign-on for all deployments. | ||
| * No license required (licenseFeature = null, always loaded). | ||
| * | ||
| * SAML 2.0 and SSO enforcement ("Require SSO") require the enterprise | ||
| * SamlModule (licenseFeature = "sso"). | ||
| */ | ||
| class SsoModule : EnterpriseModule { | ||
| override val name: String = "SSO" | ||
|
|
||
| override fun registerRoutes(route: Route) { | ||
| route.ssoRoutes() | ||
| } | ||
|
|
||
| override fun startBackgroundJobs(application: Application) { | ||
| // SSO has no background jobs | ||
| } | ||
|
|
||
| override fun stopBackgroundJobs() { | ||
| // No-op | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Derive the refresh response from the rotated token's org context.
This now uses
getFirstMembershipForUser(userId), so a multi-org user can receiveorganizationSlug/orgRolefor a different org than thetokenPair.accessTokenyou just issued. After refresh, the client can end up rendering the wrong org context or role until the next full reload.🔧 Suggested fix
val decodedJWT = jwtVerifier.verify(tokenPair.accessToken) val userId = decodedJWT.getClaim("userId").asInt() val email = decodedJWT.getClaim("email").asString() + val orgId = decodedJWT.getClaim("orgId").asInt() + val orgRole = decodedJWT.getClaim("orgRole").asString() val user = run { val userRow = userRepository.findById(userId) ?: return null - val membership = membershipRepository.getFirstMembershipForUser(userId) - val organizationSlug = - membership?.let { organizationRepository.findById(it.organizationId)?.slug } + val organizationSlug = organizationRepository.findById(orgId)?.slug UserResponse( id = userId, email = email, name = userRow.name, emailVerified = userRow.emailVerified, onboardingCompleted = userRow.onboardingCompleted, isAdmin = userRow.isAdmin, organizationSlug = organizationSlug, - orgRole = membership?.role, + orgRole = orgRole, ) }🤖 Prompt for AI Agents