screwdriver-api 8.0.183 → 8.0.184

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screwdriver-api",
3
- "version": "8.0.183",
3
+ "version": "8.0.184",
4
4
  "description": "API server for the Screwdriver.cd service",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -27,7 +27,16 @@ server.register({
27
27
  ### Routes
28
28
 
29
29
  #### Returns an access token to talk to coverage server
30
- `GET /coverage/token?scope=job&projectKey=job:123&projectName=d2lam/mytest&username=user-job-123`
30
+ `GET /coverage/token?projectKey=job:123`
31
+
32
+ `scope`, `projectName`, and `username` are not accepted as query parameters — all three are always resolved
33
+ server-side from the build's own JWT-verified identity. `projectKey` is rejected with a `403` unless it
34
+ names a project the calling build is authorized for (its own pipeline, its own job, or its PR parent job)
35
+ **and** matches the build's own resolved coverage scope.
36
+
37
+ > **Deployment order:** requires `screwdriver-coverage-sonar` ≥6.0.0
38
+ > ([coverage-sonar#80](https://github.com/screwdriver-cd/coverage-sonar/pull/80)). This API change must be
39
+ > deployed *before* that dependency is bumped — see that PR's README for why.
31
40
 
32
41
  #### Get an object with coverage info
33
42
 
@@ -22,26 +22,20 @@ module.exports = config => ({
22
22
  const { jobFactory, pipelineFactory } = request.server.app;
23
23
  const buildCredentials = request.auth.credentials;
24
24
  const { jobId, pipelineId } = buildCredentials;
25
- const { scope, projectKey, projectName, username, selfSonarHost, selfSonarAdminToken } = request.query;
25
+ const { projectKey, selfSonarHost, selfSonarAdminToken } = request.query;
26
+ // `scope`, `projectName`, and `username` are deliberately not read from the query. The coverage
27
+ // plugin derives all three from records resolved below via the build's own JWT-verified ids, so
28
+ // a build cannot override which Sonar project or scope its token/Git App binding applies to.
26
29
  const tokenConfig = {
27
- buildCredentials,
28
- scope
30
+ buildCredentials
29
31
  };
30
32
 
31
33
  if (projectKey) {
32
34
  tokenConfig.projectKey = projectKey;
33
35
  }
34
36
 
35
- if (projectName) {
36
- tokenConfig.projectName = projectName;
37
- }
38
-
39
- if (username) {
40
- tokenConfig.username = username;
41
- }
42
-
43
- // Get scope and job name
44
- if (jobId && !scope) {
37
+ // Get scope and job name; always resolved here so neither can be supplied by the caller
38
+ if (jobId) {
45
39
  const job = await jobFactory.get(jobId);
46
40
 
47
41
  if (!job) {
@@ -49,6 +43,13 @@ module.exports = config => ({
49
43
  }
50
44
 
51
45
  tokenConfig.jobName = job.name;
46
+ // Invariant this rejection below relies on: screwdriver-cd/launcher's coverage/info call
47
+ // (launch.go, GetCoverageInfo) reads this exact field/index -
48
+ // job.Permutations[0].Annotations.CoverageScope - and always sends it as `scope`, empty
49
+ // string when absent, never omitted (screwdriver.go's CoverageURL has no projectKey param
50
+ // at all). So the scope screwdriver-coverage-sonar resolved when it minted
51
+ // SD_SONAR_PROJECT_KEY and the annotation re-read here cannot disagree for a real build,
52
+ // short of a pipeline sync rewriting this annotation between build start and this request.
52
53
  tokenConfig.scope =
53
54
  job.permutations[0] && job.permutations[0].annotations
54
55
  ? job.permutations[0].annotations[COVERAGE_SCOPE_ANNOTATION]
@@ -56,8 +57,8 @@ module.exports = config => ({
56
57
  }
57
58
  let pipeline;
58
59
 
59
- // Get pipeline name
60
- if (pipelineId && (!projectName || projectName.includes('undefined'))) {
60
+ // Get pipeline name; always resolved here so it can never be supplied by the caller
61
+ if (pipelineId) {
61
62
  pipeline = await pipelineFactory.get(pipelineId);
62
63
 
63
64
  if (!pipeline) {
@@ -91,12 +92,6 @@ module.exports = config => ({
91
92
  const data = await config.coveragePlugin.getAccessToken(tokenConfig);
92
93
  const { projectUrl } = config.coveragePlugin.getProjectData(tokenConfig);
93
94
 
94
- if (!pipeline && pipelineId) {
95
- pipeline = await pipelineFactory.get(pipelineId);
96
-
97
- logger.info(`looking up again, pipeline:${pipelineId}, and found pipeline: ${pipeline}`);
98
- }
99
-
100
95
  if (pipeline && projectUrl) {
101
96
  try {
102
97
  const pipelineSonarBadge = {