* Run gcpAuthRefresh to perform interactive authentication (e.g., gcloud auth application-default login) * Streams output in real-time for user visibility
()
| 947 | * Streams output in real-time for user visibility |
| 948 | */ |
| 949 | async function runGcpAuthRefresh(): Promise<boolean> { |
| 950 | const gcpAuthRefresh = getConfiguredGcpAuthRefresh() |
| 951 | |
| 952 | if (!gcpAuthRefresh) { |
| 953 | return false // Not configured, treat as success |
| 954 | } |
| 955 | |
| 956 | // SECURITY: Check if gcpAuthRefresh is from project settings |
| 957 | if (isGcpAuthRefreshFromProjectSettings()) { |
| 958 | // Check if trust has been established for this project |
| 959 | // Pass true to indicate this is a dangerous feature that requires trust |
| 960 | const hasTrust = checkHasTrustDialogAccepted() |
| 961 | if (!hasTrust && !getIsNonInteractiveSession()) { |
| 962 | const error = new Error( |
| 963 | `Security: gcpAuthRefresh executed before workspace trust is confirmed. If you see this message, post in ${MACRO.FEEDBACK_CHANNEL}.`, |
| 964 | ) |
| 965 | logAntError('gcpAuthRefresh invoked before trust check', error) |
| 966 | logEvent('ncode_gcpAuthRefresh_missing_trust', {}) |
| 967 | return false |
| 968 | } |
| 969 | } |
| 970 | |
| 971 | try { |
| 972 | logForDebugging('Checking GCP credentials validity for auth refresh') |
| 973 | const isValid = await checkGcpCredentialsValid() |
| 974 | if (isValid) { |
| 975 | logForDebugging( |
| 976 | 'GCP credentials are valid, skipping auth refresh command', |
| 977 | ) |
| 978 | return false |
| 979 | } |
| 980 | } catch { |
| 981 | // Credentials check failed, proceed with refresh |
| 982 | } |
| 983 | |
| 984 | return refreshGcpAuth(gcpAuthRefresh) |
| 985 | } |
| 986 | |
| 987 | // Timeout for GCP auth refresh command (3 minutes). |
| 988 | // Long enough for browser-based auth flows, short enough to prevent indefinite hangs. |
no test coverage detected