Skip to content
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

Property 'httpAuth' does not exist on type 'PluginEnvironment'. #100

Open
hirveakshata opened this issue May 13, 2024 · 8 comments
Open

Comments

@hirveakshata
Copy link

Getting an error when I added s3.ts file in backstage/packages/backend/scr/plugins.
import { S3Builder } from '@spreadshirt/backstage-plugin-s3-viewer-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';
export default async function createPlugin(
env: PluginEnvironment,
): Promise {
const { router } = await S3Builder.createBuilder({
auth: env.auth,
config: env.config,
logger: env.logger,
scheduler: env.scheduler,
discovery: env.discovery,
permissions: env.permissions,
httpAuth: env.httpAuth,
}).build();
return router;
}

@ivangonzalezacuna
Copy link
Collaborator

Which plugin version are you using? These 2 types you're mentioning have been added in some of the latest releases. In the latest, at least, I can tell that they are part of the type S3Environment.

If the case is that your environment doesn't have such fields (which I guess that's the root cause) I would suggest 2 things:

  • Use the new backend system. It's the standard now and this plugin supports it since a few releases
  • Make sure you create the missing auth and httpAuth from your environment. How?:
  const { auth, httpAuth } = createLegacyAuthAdapters(env);

  const { router } = await S3Builder.createBuilder({
    ...env,
    auth,
    httpAuth,
  }).build();

This is what the plugin does in the new backend system, and it has been working so far. If that fixes the issue, I could update the documentation so others using the old backend setup don't have the same issue

@hirveakshata
Copy link
Author

I'm using the old backend and have not yet moved to a new backend setup. The solution you have provided, could you please guide me exactly where I should add it? I have tried to add these in type.ts and index.ts but still didn't work out.
import { AuthService, HttpAuthService } from '@backstage/backend-plugin-api';

export type PluginEnvironment = {
auth: AuthService;
httpAuth: HttpAuthService;
logger: Logger;
database: PluginDatabaseManager;
cache: PluginCacheManager;
config: Config;
reader: UrlReader;
discovery: PluginEndpointDiscovery;
tokenManager: TokenManager;
scheduler: PluginTaskScheduler;
permissions: PermissionEvaluator;
identity: IdentityApi;
};
index.ts
eturn {
logger,
database,
cache,
config,
reader,
discovery,
tokenManager,
scheduler,
permissions,
identity,
auth,
httpAuth
};

@ivangonzalezacuna
Copy link
Collaborator

ivangonzalezacuna commented May 13, 2024

You should have to add it in your s3.ts file. Right before doing the S3Builder.createBuilder. The line const { auth, httpAuth } = createLegacyAuthAdapters(env); is making sure the 2 parameters are generated without needing you to extend your plugin environment. Afterwards, you only need to send all your environment plus those 2 parameters, and it should work again.

The line mentioned above is coming from the tutorial in backstage: https://backstage.io/docs/tutorials/auth-service-migration

@hirveakshata
Copy link
Author

Although you have suggested a new backend system as a solution, the old backend system is still having problems. The auth and httpAuth methods that you are utilizing in S3Environment are incompatible with the old backend.

I appreciate your response.

@ivangonzalezacuna
Copy link
Collaborator

What about doing this. I've just tested it in my local backstage:

Extend your environment:

// in packages/backend/src/types.ts

import { Logger } from 'winston';
import { Config } from '@backstage/config';
import {
  AuthService,
  DatabaseService,
  DiscoveryService,
  HttpAuthService,
  TokenManagerService,
  UrlReaderService,
} from '@backstage/backend-plugin-api';
import { PluginTaskScheduler } from '@backstage/backend-tasks';
import { PermissionEvaluator } from '@backstage/plugin-permission-common';
import { IdentityApi } from '@backstage/plugin-auth-node';
import { PluginCacheManager } from '@backstage/backend-common';

export type PluginEnvironment = {
  auth?: AuthService; // add this optional
  httpAuth?: HttpAuthService; // add this optional
  logger: Logger;
  database: DatabaseService;
  cache: PluginCacheManager;
  config: Config;
  reader: UrlReaderService;
  discovery: DiscoveryService;
  tokenManager: TokenManagerService;
  scheduler: PluginTaskScheduler;
  permissions: PermissionEvaluator;
  identity: IdentityApi;
};

Define your plugin:

// in packages/backend/src/plugins/s3.ts
import { createLegacyAuthAdapters } from '@backstage/backend-common';
import { PluginEnvironment } from '../types';
import { S3Builder } from '@spreadshirt/backstage-plugin-s3-viewer-backend';
import { Router } from 'express';

export default async function createPlugin(
  env: PluginEnvironment,
): Promise<Router> {
  const { auth, httpAuth } = createLegacyAuthAdapters(env);

  const { router } = await S3Builder.createBuilder({
    ...env,
    auth,
    httpAuth,
  }).build();

  return router;
}

@hirveakshata
Copy link
Author

Thank you for providing the solution. It functions.
I'm unable to see any records. I have included the following code in the app.config.yaml file. Replace the access and secret keys with mine.
s3:
bucketLocatorMethods:
- type: config
platforms:
- endpoint: http://endpoint-one.com
name: endpoint-one-name
region: us-east-1
accessKeyId: ${ENDPOINT_ONE_ACCESS_KEY}
secretAccessKey: ${ENDPOINT_ONE_SECRET_KEY}
- endpoint: http://endpoint-two.com
name: endpoint-two-name
region: us-east-1
accessKeyId: ${ENDPOINT_TWO_ACCESS_KEY}
secretAccessKey: ${ENDPOINT_TWO_SECRET_KEY}
- type: radosgw-admin
platforms:
- endpoint: http://radosgw-endpoint.com
name: radosgw-endpoint-name
region: us-east-1
accessKeyId: ${RADOSGW_ACCESS_KEY}
secretAccessKey: ${RADOSGW_SECRET_KEY}
- type: iam-role
platforms:
- endpoint: http://iam-endpoint.com
name: iam-endpoint-name
region: us-east-1
allowedBuckets:
- platform: endpoint-one-name
buckets:
- allowed-bucket-one
- allowed-bucket-two
- platform: radosgw-endpoint-name
buckets:
- other-allowed-bucket
- platform: iam-endpoint-name
buckets:
- another-bucket-name
bucketRefreshSchedule:
frequency: { minutes: 30 }
timeout: { minutes: 1 }

@ivangonzalezacuna
Copy link
Collaborator

I believe this might be an issue with backstage itself. I was just checking the release notes from the version 1.27.0, and found out a change about the legacyPlugin: https://github.com/backstage/backstage/blob/master/docs/releases/v1.27.0-changelog.md#backstagebackend-common0220. Looks like there might have been an issue with the authentication signing for plugins not using the new backend setup. But cannot confirm it yet unfortunately. The only solution would be bumping the dependencies for this plugin and verify that it got fixed afterwards.

Anyways, just to double check, have you added the needed code to make the permissions work? That's what is explained here: https://github.com/spreadshirt/backstage-plugin-s3/tree/main/plugins/s3-viewer-backend#permissions-setup

@hirveakshata
Copy link
Author

Thanks. I'll try to add the permission code; possibly, this will function after that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants