GithubHelp home page GithubHelp logo

Comments (8)

ivangonzalezacuna avatar ivangonzalezacuna commented on June 26, 2024 1

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;
}

from backstage-plugin-s3.

ivangonzalezacuna avatar ivangonzalezacuna commented on June 26, 2024

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

from backstage-plugin-s3.

hirveakshata avatar hirveakshata commented on June 26, 2024

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
};

from backstage-plugin-s3.

ivangonzalezacuna avatar ivangonzalezacuna commented on June 26, 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

from backstage-plugin-s3.

hirveakshata avatar hirveakshata commented on June 26, 2024

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.

from backstage-plugin-s3.

hirveakshata avatar hirveakshata commented on June 26, 2024

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 }

from backstage-plugin-s3.

ivangonzalezacuna avatar ivangonzalezacuna commented on June 26, 2024

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

from backstage-plugin-s3.

hirveakshata avatar hirveakshata commented on June 26, 2024

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

from backstage-plugin-s3.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.