Skip to content

Commit a8b0fcc

Browse files
Merge branch 'main' into cursor/weekly-release-v1.3.0-231a
2 parents 319ea26 + 7b8ea65 commit a8b0fcc

7 files changed

Lines changed: 138 additions & 4 deletions

File tree

backend/src/main/java/com/dbaagent/controller/SetupController.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.dbaagent.service.SystemConfigService;
77
import lombok.RequiredArgsConstructor;
88
import lombok.extern.slf4j.Slf4j;
9+
import org.springframework.beans.factory.annotation.Value;
910
import org.springframework.http.ResponseEntity;
1011
import org.springframework.web.bind.annotation.*;
1112
import org.springframework.web.client.RestClient;
@@ -34,6 +35,25 @@ public class SetupController {
3435
private final CredentialRepository credentialRepository;
3536
private final LlmConfigResolver llmConfigResolver;
3637

38+
/**
39+
* Mirrors {@code security.google.enabled}. Surfaced on the public status
40+
* endpoint so the login page can decide whether to offer Google sign-in —
41+
* it is otherwise unauthenticated and has no way to know the server was
42+
* configured for SSO. Deliberately NOT final: {@code @RequiredArgsConstructor}
43+
* would pull a final field into the constructor and Spring has no bean to
44+
* satisfy it.
45+
*/
46+
@Value("${security.google.enabled:false}")
47+
private boolean googleEnabled;
48+
49+
/**
50+
* Mirrors {@code security.password.enabled}. Lets the login page hide the
51+
* email/password form on SSO-only installs instead of rendering a form that
52+
* always fails. Same non-final reasoning as above.
53+
*/
54+
@Value("${security.password.enabled:true}")
55+
private boolean passwordLoginEnabled;
56+
3757
// ── GET /setup/status ─────────────────────────────────────────────────────
3858

3959
/** Returns setup completion state. Public endpoint — no auth required. */
@@ -53,7 +73,9 @@ public SetupStatusResponse getStatus() {
5373
setupComplete,
5474
hasOrgInfo,
5575
hasConnections,
56-
hasLlmConfig
76+
hasLlmConfig,
77+
googleEnabled,
78+
passwordLoginEnabled
5779
);
5880
}
5981

@@ -278,7 +300,11 @@ public record SetupStatusResponse(
278300
boolean setupComplete,
279301
boolean hasOrganizationInfo,
280302
boolean hasConnections,
281-
boolean hasLlmConfig
303+
boolean hasLlmConfig,
304+
/** Whether Google Workspace SSO is configured; drives the login page's SSO button. */
305+
boolean googleEnabled,
306+
/** Whether email+password sign-in is accepted; false hides the password form. */
307+
boolean passwordLoginEnabled
282308
) {}
283309

284310
public record InitializeRequest(String orgName, String adminUsername, String adminEmail, String adminPassword) {}

backend/src/main/java/com/dbaagent/service/PasswordlessAuthService.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import com.dbaagent.repository.*;
55
import com.dbaagent.security.EncryptionService;
66
import com.dbaagent.util.SecurityHashUtil;
7+
import jakarta.annotation.PostConstruct;
78
import lombok.Builder;
89
import lombok.RequiredArgsConstructor;
10+
import lombok.extern.slf4j.Slf4j;
911
import org.springframework.beans.factory.annotation.Value;
1012
import org.springframework.http.HttpStatus;
1113
import org.springframework.http.MediaType;
@@ -25,6 +27,7 @@
2527

2628
@Service
2729
@RequiredArgsConstructor
30+
@Slf4j
2831
public class PasswordlessAuthService {
2932
private static final SecureRandom RANDOM = new SecureRandom();
3033

@@ -72,6 +75,32 @@ public class PasswordlessAuthService {
7275
@Value("${security.google.enabled:false}")
7376
private boolean googleEnabled;
7477

78+
/**
79+
* Whether email + password sign-in is accepted at all.
80+
*
81+
* <p>Defaults to {@code true} so existing installs are unaffected. Set it to
82+
* false on deployments that front DeepSQL with Google Workspace SSO: enabling
83+
* SSO does NOT by itself close the password path, so without this flag
84+
* {@code /auth/login} stays open to every local account even when every human
85+
* signs in through Google.
86+
*
87+
* <p>Turning this off while {@code security.google.enabled} is also off leaves
88+
* no way to sign in — {@link #warnIfNoAuthMethodEnabled()} shouts about that at
89+
* startup rather than letting it be discovered at the login screen.
90+
*/
91+
@Value("${security.password.enabled:true}")
92+
private boolean passwordLoginEnabled;
93+
94+
@PostConstruct
95+
void warnIfNoAuthMethodEnabled() {
96+
if (!passwordLoginEnabled && !googleEnabled) {
97+
log.error("security.password.enabled=false AND security.google.enabled=false — "
98+
+ "no sign-in method is available and nobody can log in. Enable one of them.");
99+
} else if (!passwordLoginEnabled) {
100+
log.info("Password sign-in is DISABLED (security.password.enabled=false); Google SSO only.");
101+
}
102+
}
103+
75104
@Value("${security.google.client-id:}")
76105
private String googleClientId;
77106

@@ -87,6 +116,23 @@ public class PasswordlessAuthService {
87116
@Transactional
88117
public AuthFlowResult loginWithPassword(String email, String password, String clientIp, String userAgent, String requestId) {
89118
String normalizedEmail = normalizeEmail(email);
119+
120+
// Checked before the rate limiter and before any credential comparison:
121+
// when the password path is closed there is nothing to rate-limit and no
122+
// secret to compare, and we must not leak whether the account exists.
123+
if (!passwordLoginEnabled) {
124+
securityEventService.log(SecurityEventService.EventRequest.builder()
125+
.eventType(SecurityEventType.PASSWORD_LOGIN_FAILURE)
126+
.outcome(SecurityEventOutcome.FAILURE)
127+
.email(normalizedEmail)
128+
.clientIp(clientIp)
129+
.userAgent(userAgent)
130+
.requestId(requestId)
131+
.metadata(Map.of("reason", "password_login_disabled"))
132+
.build());
133+
return AuthFlowResult.invalid("Password sign-in is disabled. Please sign in with Google.");
134+
}
135+
90136
if (rateLimitEnabled) enforcePasswordRateLimit(normalizedEmail, clientIp);
91137

92138
User user = normalizedEmail == null ? null : userRepository.findByEmailIgnoreCase(normalizedEmail).orElse(null);

backend/src/main/resources/application-prod.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ spring.threads.virtual.enabled=true
77

88
# Security Configuration - set to false to bypass authentication
99
security.auth.enabled=true
10+
security.password.enabled=${SECURITY_PASSWORD_ENABLED:true}
1011
security.jwt.secret=${SECURITY_JWT_SECRET:}
1112
# First-user bootstrap. Off by default: the endpoint creates an ADMIN without
1213
# authenticating, so it stays shut unless someone is deliberately installing.

backend/src/main/resources/application.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ spring.threads.virtual.enabled=true
1616
# matches production behavior. Override with SECURITY_AUTH_ENABLED=false only
1717
# for explicit single-user bypass scenarios.
1818
security.auth.enabled=${SECURITY_AUTH_ENABLED:true}
19+
# Email+password sign-in. Defaults true so existing installs are unaffected.
20+
# Set false on SSO-only deployments: enabling Google does NOT close /auth/login.
21+
security.password.enabled=${SECURITY_PASSWORD_ENABLED:true}
1922
security.admin-mfa.enabled=${SECURITY_ADMIN_MFA_ENABLED:false}
2023
security.jwt.secret=${SECURITY_JWT_SECRET:}
2124
security.admin.bootstrap.enabled=${SECURITY_ADMIN_BOOTSTRAP_ENABLED:false}

backend/src/test/java/com/dbaagent/service/PasswordlessAuthServiceTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ void setUp() {
5757
ReflectionTestUtils.setField(service, "maxIpStarts", 20);
5858
ReflectionTestUtils.setField(service, "maxPasswordFailures", 10);
5959
ReflectionTestUtils.setField(service, "adminMfaEnabled", false);
60+
// @Value is not processed by @InjectMocks, so a boolean field defaults to
61+
// false. Unlike rateLimitEnabled (checked as `if (enabled)`, so absence
62+
// merely skips it), password login is checked as `if (!enabled)` — leaving
63+
// it unset would reject every login below.
64+
ReflectionTestUtils.setField(service, "passwordLoginEnabled", true);
6065

6166
when(authLoginChallengeRepository.save(any(AuthLoginChallenge.class)))
6267
.thenAnswer(invocation -> invocation.getArgument(0));

src/lib/api/client.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3682,7 +3682,8 @@ export const setupAPI = {
36823682

36833683
/**
36843684
* Returns current setup state: setupComplete, hasOrganizationInfo,
3685-
* hasConnections, hasLlmConfig. Public endpoint — no auth required.
3685+
* hasConnections, hasLlmConfig, googleEnabled, passwordLoginEnabled.
3686+
* Public endpoint — no auth required.
36863687
*/
36873688
getStatus: async () => {
36883689
const response = await apiClient.get("/api/setup/status");

src/pages/Login.jsx

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,15 @@ export default function Login() {
9898
}
9999

100100

101+
// Default to showing the password form: setupStatus is null on first paint and
102+
// while the request is in flight, and an install that never set the flag gets
103+
// `undefined`. Both must render the form, or a slow/failed status call would
104+
// strand everyone on a login page with no way in.
105+
const passwordLoginEnabled = setupStatus?.passwordLoginEnabled !== false
106+
101107
const renderLoginStep = () => (
108+
<>
109+
{passwordLoginEnabled && (
102110
<form onSubmit={handlePasswordLogin} className="space-y-5">
103111
<div>
104112
<label htmlFor="email" className="text-xs font-semibold text-gray-500 uppercase tracking-wider block mb-1.5">
@@ -147,6 +155,48 @@ export default function Login() {
147155
{loading ? 'Signing in…' : 'Sign In'}
148156
</button>
149157
</form>
158+
)}
159+
160+
{/*
161+
Only rendered when the server reports security.google.enabled. The login
162+
page is unauthenticated, so /setup/status (already public, already fetched
163+
above) is how it learns SSO exists — otherwise this button would 500 for
164+
every install that never configured Google.
165+
166+
A plain <a>, not a button: /api/auth/google/start issues a 302 to Google,
167+
so this is a full-page navigation and must not submit the form above.
168+
*/}
169+
{setupStatus?.googleEnabled && (
170+
<div className={passwordLoginEnabled ? 'mt-6' : ''}>
171+
{/* The divider only separates two things — drop it when SSO stands alone. */}
172+
{passwordLoginEnabled && (
173+
<div className="relative">
174+
<div className="absolute inset-0 flex items-center" aria-hidden="true">
175+
<div className="w-full border-t border-gray-200" />
176+
</div>
177+
<div className="relative flex justify-center">
178+
<span className="bg-white px-3 text-xs font-medium uppercase tracking-wider text-gray-400">
179+
or
180+
</span>
181+
</div>
182+
</div>
183+
)}
184+
185+
<a
186+
href={authAPI.getGoogleStartUrl()}
187+
className={`${passwordLoginEnabled ? 'mt-6' : ''} w-full min-h-[48px] flex items-center justify-center gap-3 bg-white border border-gray-300 hover:bg-gray-50 text-gray-700 font-semibold py-3 rounded-full shadow-sm transition-all active:scale-[0.98]`}
188+
>
189+
<svg className="h-5 w-5" viewBox="0 0 24 24" aria-hidden="true">
190+
<path fill="#4285F4" d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 0 1-2.2 3.32v2.76h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" />
191+
<path fill="#34A853" d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.76c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84A11 11 0 0 0 12 23z" />
192+
<path fill="#FBBC05" d="M5.84 14.11a6.6 6.6 0 0 1 0-4.22V7.05H2.18a11 11 0 0 0 0 9.9l3.66-2.84z" />
193+
<path fill="#EA4335" d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1a11 11 0 0 0-9.82 6.05l3.66 2.84c.87-2.6 3.3-4.51 6.16-4.51z" />
194+
</svg>
195+
Sign in with Google
196+
</a>
197+
</div>
198+
)}
199+
</>
150200
)
151201

152202
const renderOtpStep = () => (
@@ -211,7 +261,9 @@ export default function Login() {
211261
const stepTitle = step === STEP_OTP ? 'Verify your sign-in' : 'Secure sign-in'
212262
const stepSubtitle = step === STEP_OTP
213263
? 'Complete the extra email verification step for this workspace.'
214-
: 'Sign in with your email and password to access DeepSQL.'
264+
: passwordLoginEnabled
265+
? 'Sign in with your email and password to access DeepSQL.'
266+
: 'Sign in with your work Google account to access DeepSQL.'
215267

216268
return (
217269
<div className="flex min-h-screen w-full bg-white text-gray-900 overflow-x-hidden">

0 commit comments

Comments
 (0)